diff --git a/BizHawk.Emulation/BizHawk.Emulation.csproj b/BizHawk.Emulation/BizHawk.Emulation.csproj index 965b894aeb..e25d81f431 100644 --- a/BizHawk.Emulation/BizHawk.Emulation.csproj +++ b/BizHawk.Emulation/BizHawk.Emulation.csproj @@ -132,6 +132,7 @@ + @@ -162,6 +163,7 @@ + diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs index 4b28712634..4cb533811b 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Core.cs @@ -11,19 +11,11 @@ namespace BizHawk.Emulation.Computers.Commodore64 PAL } - public partial class C64 : IEmulator + public partial class C64 : IEmulator { - // ------------------------------------ - private Motherboard board; - //private VIC1541 disk; - - // ------------------------------------ - private bool loadPrg; - // ------------------------------------ - private byte[] GetFirmware(string name, int length) { byte[] result = new byte[length]; @@ -39,7 +31,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 board = new Motherboard(initRegion); InitRoms(); board.Init(); - InitDisk(initRegion); InitMedia(); // configure video @@ -47,27 +38,19 @@ namespace BizHawk.Emulation.Computers.Commodore64 CoreComm.VsyncNum = board.vic.CyclesPerSecond; } - private void InitDisk(Region initRegion) - { - byte[] diskRom = new byte[0x4000]; //GetFirmware("dos1541", 0x4000); - - //disk = new VIC1541(initRegion, diskRom); - //disk.Connect(board.serPort); - } - private void InitMedia() { - switch (extension.ToUpper()) + switch (inputFileInfo.Extension.ToUpper()) { case @".CRT": - Cart cart = Cart.Load(inputFile); + Cart cart = Cart.Load(inputFileInfo.Data); if (cart != null) { board.cartPort.Connect(cart); } break; case @".PRG": - if (inputFile.Length > 2) + if (inputFileInfo.Data.Length > 2) loadPrg = true; break; } @@ -100,8 +83,6 @@ namespace BizHawk.Emulation.Computers.Commodore64 board.HardReset(); //disk.HardReset(); } - - // ------------------------------------ } static public class C64Util diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs index 8abbd3f9a9..b73f304509 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Input.cs @@ -4,8 +4,8 @@ namespace BizHawk.Emulation.Computers.Commodore64 { public partial class Motherboard { - private bool[,] joystickPressed = new bool[2, 5]; - private bool[,] keyboardPressed = new bool[8, 8]; + private int[] joystickPressed = new int[10]; + private int[] keyboardPressed = new int[64]; static private string[,] joystickMatrix = new string[2, 5] { @@ -28,26 +28,29 @@ namespace BizHawk.Emulation.Computers.Commodore64 static private byte[] inputBitMask = new byte[] { 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F }; static private byte[] inputBitSelect = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; - private byte cia0InputLatchA; - private byte cia0InputLatchB; + protected byte cia0InputLatchA; + protected byte cia0InputLatchB; + protected int pollIndex; public void PollInput() { // scan joysticks - for (int i = 0; i < 2; i++) + pollIndex = 0; + for (int j = 0; j < 5; j++) { - for (int j = 0; j < 5; j++) - { - joystickPressed[i, j] = controller[joystickMatrix[i, j]]; + for (int i = 0; i < 2; i++) + { + joystickPressed[pollIndex++] = controller[joystickMatrix[i, j]] ? -1 : 0; } } // scan keyboard + pollIndex = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { - keyboardPressed[i, j] = controller[keyboardMatrix[i, j]]; + keyboardPressed[pollIndex++] = controller[keyboardMatrix[i, j]] ? -1 : 0; } } } @@ -61,11 +64,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 byte joyA = 0xFF; byte joyB = 0xFF; + pollIndex = 0; for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { - if (keyboardPressed[i, j]) + if (keyboardPressed[pollIndex++] != 0) { if (((portA & inputBitSelect[i]) == 0) || ((portB & inputBitSelect[j]) == 0)) { @@ -76,12 +80,13 @@ namespace BizHawk.Emulation.Computers.Commodore64 } } + pollIndex = 0; for (int i = 0; i < 5; i++) { - if (joystickPressed[1, i]) + if (joystickPressed[pollIndex++] != 0) + joyB &= inputBitMask[i]; + if (joystickPressed[pollIndex++] != 0) joyA &= inputBitMask[i]; - if (joystickPressed[0, i]) - joyB &= inputBitMask[i]; } resultA &= joyA; diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs index 78ada27fbf..7dfc802882 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Motherboard.cs @@ -1,4 +1,5 @@ using BizHawk.Emulation.Computers.Commodore64.MOS; +using System.Reflection; namespace BizHawk.Emulation.Computers.Commodore64 { @@ -195,6 +196,49 @@ namespace BizHawk.Emulation.Computers.Commodore64 public void SyncState(Serializer ser) { - } + ser.BeginSection("motherboard"); + Sync.SyncObject(ser, this); + ser.EndSection(); + + ser.BeginSection("cartridge"); + cartPort.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("cassette"); + cassPort.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("cia0"); + cia0.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("cia1"); + cia1.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("colorram"); + colorRam.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("cpu"); + cpu.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("pla"); + pla.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("ram"); + ram.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("sid"); + sid.SyncState(ser); + ser.EndSection(); + + ser.BeginSection("vic"); + vic.SyncState(ser); + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.Savestate.cs b/BizHawk.Emulation/Computers/Commodore64/C64.Savestate.cs index ff3ce10060..e33f4466b1 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.Savestate.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.Savestate.cs @@ -51,11 +51,9 @@ namespace BizHawk.Emulation.Computers.Commodore64 void SyncState(Serializer ser) { - board.SyncState(ser); - ser.BeginSection("core"); - ser.Sync("cyclesPerFrame", ref cyclesPerFrame); - ser.Sync("loadPrg", ref loadPrg); - ser.EndSection(); - } + ser.BeginSection("core"); + board.SyncState(ser); + ser.EndSection(); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/C64.cs b/BizHawk.Emulation/Computers/Commodore64/C64.cs index 66f259bad0..ab6f32c666 100644 --- a/BizHawk.Emulation/Computers/Commodore64/C64.cs +++ b/BizHawk.Emulation/Computers/Commodore64/C64.cs @@ -7,25 +7,12 @@ namespace BizHawk.Emulation.Computers.Commodore64 { public partial class C64 : IEmulator { - private int cyclesPerFrame; - private string extension; - private byte[] inputFile; - - public C64(CoreComm comm, GameInfo game, byte[] rom, string romextension) - { - CoreComm = comm; - inputFile = rom; - extension = romextension; - Init(Region.PAL); - cyclesPerFrame = board.vic.CyclesPerFrame; - CoreComm.UsesDriveLed = true; - SetupMemoryDomains(); - } - // internal variables private bool _islag = true; private int _lagcount = 0; private int _frame = 0; + private int cyclesPerFrame; + private InputFileInfo inputFileInfo; // bizhawk I/O public CoreComm CoreComm { get; private set; } @@ -63,7 +50,7 @@ namespace BizHawk.Emulation.Computers.Commodore64 public IController Controller { get { return board.controller; } set { board.controller = value; } } public static readonly ControllerDefinition C64ControllerDefinition = new ControllerDefinition { - Name = "Commodore 64 Controller", //TODO + Name = "Commodore 64 Controller", BoolButtons = { "Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Key Cursor Up/Down", @@ -81,7 +68,19 @@ namespace BizHawk.Emulation.Computers.Commodore64 }; // framework - public void Dispose() + public C64(CoreComm comm, GameInfo game, byte[] rom, string romextension) + { + inputFileInfo = new InputFileInfo(); + inputFileInfo.Data = rom; + inputFileInfo.Extension = romextension; + CoreComm = comm; + Init(Region.PAL); + cyclesPerFrame = board.vic.CyclesPerFrame; + CoreComm.UsesDriveLed = true; + SetupMemoryDomains(); + } + + public void Dispose() { if (board.sid != null) { @@ -93,28 +92,36 @@ namespace BizHawk.Emulation.Computers.Commodore64 // process frame public void FrameAdvance(bool render, bool rendersound) { - // load PRG file if needed - if (loadPrg) - { - if (board.pla.Peek(0x04C8) == 0x12 && - board.pla.Peek(0x04C9) == 0x05 && - board.pla.Peek(0x04CA) == 0x01 && - board.pla.Peek(0x04CB) == 0x04 && - board.pla.Peek(0x04CC) == 0x19 && - board.pla.Peek(0x04CD) == 0x2E) - { - Media.PRG.Load(board.pla, inputFile); - loadPrg = false; - } - } - board.inputRead = false; board.PollInput(); + for (int count = 0; count < cyclesPerFrame; count++) { //disk.Execute(); board.Execute(); - } + + // load PRG file if needed + if (loadPrg) + { + // check to see if cpu PC is at the BASIC warm start vector + if (board.cpu.PC == ((board.ram.Peek(0x0303) << 8) | board.ram.Peek(0x0302))) + { + //board.ram.Poke(0x0302, 0xAE); + //board.ram.Poke(0x0303, 0xA7); + ////board.ram.Poke(0x0302, board.ram.Peek(0x0308)); + ////board.ram.Poke(0x0303, board.ram.Peek(0x0309)); + + //if (inputFileInfo.Data.Length >= 6) + //{ + // board.ram.Poke(0x0039, inputFileInfo.Data[4]); + // board.ram.Poke(0x003A, inputFileInfo.Data[5]); + //} + Media.PRG.Load(board.pla, inputFileInfo.Data); + loadPrg = false; + } + } + } + board.Flush(); _islag = !board.inputRead; diff --git a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs index c54e245d82..28ae54bdc9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs +++ b/BizHawk.Emulation/Computers/Commodore64/Cartridge/Cart.cs @@ -236,12 +236,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.Cartridge public virtual void SyncState(Serializer ser) { - ser.Sync("pinExRom", ref pinExRom); - ser.Sync("pinGame", ref pinGame); - ser.Sync("pinIRQ", ref pinIRQ); - ser.Sync("pinNMI", ref pinNMI); - ser.Sync("pinReset", ref pinReset); - ser.Sync("validCartridge", ref validCartridge); + Sync.SyncObject(ser, this); } public bool Valid diff --git a/BizHawk.Emulation/Computers/Commodore64/InputFileInfo.cs b/BizHawk.Emulation/Computers/Commodore64/InputFileInfo.cs new file mode 100644 index 0000000000..f8686553b9 --- /dev/null +++ b/BizHawk.Emulation/Computers/Commodore64/InputFileInfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Computers.Commodore64 +{ + public struct InputFileInfo + { + public byte[] Data; + public string Extension; + } +} diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs index ded620006a..8a822f9f8a 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/CartridgePort.cs @@ -8,8 +8,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public Func ReadIRQ; public Func ReadNMI; - private Cart cart; - private bool connected; + protected Cart cart; + protected bool connected; public CartridgePort() { @@ -80,13 +80,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - ser.Sync("connected", ref connected); - if (connected) - { - ser.BeginSection("cartmapper"); - cart.SyncState(ser); - ser.EndSection(); - } + Sync.SyncObject(ser, this); } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs index a3d8ba9ed6..9342b9f374 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/CassettePort.cs @@ -20,5 +20,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { return true; } + + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs index f7260516ff..4479f1c9da 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip2114.cs @@ -4,7 +4,7 @@ public class Chip2114 { - private byte[] ram; + protected byte[] ram; public Chip2114() { @@ -33,9 +33,8 @@ public void SyncState(Serializer ser) { - ByteBuffer buffer = new ByteBuffer(ram); - ser.Sync("ram", ref buffer); - } + Sync.SyncObject(ser, this); + } public void Write(int addr, byte val) { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs index 9371f814b7..37656390e4 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip23XX.cs @@ -16,8 +16,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public class Chip23XX { - private int addrMask; - private byte[] rom; + protected int addrMask; + protected byte[] rom; public Chip23XX(Chip23XXmodel model, byte[] data) { @@ -53,8 +53,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - ByteBuffer buffer = new ByteBuffer(rom); - ser.Sync("rom", ref buffer); - } + Sync.SyncObject(ser, this); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs index 4f14f04ae6..820bf4feae 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Chip4864.cs @@ -13,7 +13,7 @@ public class Chip4864 { - private byte[] ram; + protected byte[] ram; public Chip4864() { @@ -45,9 +45,8 @@ public void SyncState(Serializer ser) { - ByteBuffer buffer = new ByteBuffer(ram); - ser.Sync("ram", ref buffer); - } + Sync.SyncObject(ser, this); + } public void Write(int addr, byte val) { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs index 8a575ebf67..efd3d22d11 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6510.cs @@ -11,12 +11,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { // ------------------------------------ - private MOS6502X cpu; - private List disposeList = new List(); - //private bool freezeCpu; - private bool pinNMILast; - private LatchedPort port; - private bool thisNMI; + protected MOS6502X cpu; + protected bool pinNMILast; + protected LatchedPort port; + protected bool thisNMI; public Func PeekMemory; public Action PokeMemory; @@ -43,14 +41,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS HardReset(); } - ~MOS6510() - { - foreach (GCHandle handle in disposeList) - { - handle.Free(); - } - } - public void HardReset() { // configure CPU defaults @@ -101,6 +91,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { return cpu.PC; } + set + { + cpu.PC = value; + } } public byte Peek(int addr) @@ -148,7 +142,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { cpu.SyncState(ser); - ser.Sync("pinNMILast", ref pinNMILast); + Sync.SyncObject(ser, this); } public void Write(ushort addr, byte val) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs index 43fdb1cded..6f7631d4f3 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6526.cs @@ -12,7 +12,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { // ------------------------------------ - private enum InMode + protected enum InMode { Phase2, CNT, @@ -20,26 +20,26 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS TimerAUnderflowCNT } - private enum OutMode + protected enum OutMode { Pulse, Toggle } - private enum RunMode + protected enum RunMode { Continuous, Oneshot } - private enum SPMode + protected enum SPMode { Input, Output } - private static byte[] PBOnBit = new byte[] { 0x40, 0x80 }; - private static byte[] PBOnMask = new byte[] { 0xBF, 0x7F }; + protected static byte[] PBOnBit = new byte[] { 0x40, 0x80 }; + protected static byte[] PBOnMask = new byte[] { 0xBF, 0x7F }; // ------------------------------------ @@ -49,36 +49,36 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - private bool alarmSelect; - private Region chipRegion; - private bool cntPos; - private bool enableIntAlarm; - private bool enableIntFlag; - private bool enableIntSP; - private bool[] enableIntTimer; - private bool intAlarm; - private bool intFlag; - private bool intSP; - private bool[] intTimer; - private bool pinCnt; - private bool pinCntLast; - private bool pinPC; - private bool pinSP; - private byte sr; - private int[] timerDelay; - private InMode[] timerInMode; - private OutMode[] timerOutMode; - private bool[] timerPortEnable; - private bool[] timerPulse; - private RunMode[] timerRunMode; - private SPMode timerSPMode; - private byte[] tod; - private byte[] todAlarm; - private bool todAlarmPM; - private int todCounter; - private int todCounterLatch; - private bool todIn; - private bool todPM; + protected bool alarmSelect; + protected Region chipRegion; + protected bool cntPos; + protected bool enableIntAlarm; + protected bool enableIntFlag; + protected bool enableIntSP; + protected bool[] enableIntTimer; + protected bool intAlarm; + protected bool intFlag; + protected bool intSP; + protected bool[] intTimer; + protected bool pinCnt; + protected bool pinCntLast; + protected bool pinPC; + protected bool pinSP; + protected byte sr; + protected int[] timerDelay; + protected InMode[] timerInMode; + protected OutMode[] timerOutMode; + protected bool[] timerPortEnable; + protected bool[] timerPulse; + protected RunMode[] timerRunMode; + protected SPMode timerSPMode; + protected byte[] tod; + protected byte[] todAlarm; + protected bool todAlarmPM; + protected int todCounter; + protected int todCounterLatch; + protected bool todIn; + protected bool todPM; // ------------------------------------ @@ -541,67 +541,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - int chipRegionInt = (int)chipRegion; - int timerInModeInt0 = (int)timerInMode[0]; - int timerInModeInt1 = (int)timerInMode[1]; - int timerOutModeInt0 = (int)timerOutMode[0]; - int timerOutModeInt1 = (int)timerOutMode[1]; - int timerRunModeInt0 = (int)timerRunMode[0]; - int timerRunModeInt1 = (int)timerRunMode[1]; - int timerSPModeInt = (int)timerSPMode; - - SyncInternal(ser); - ser.Sync("alarmSelect", ref alarmSelect); - ser.Sync("chipRegion", ref chipRegionInt); - ser.Sync("cntPos", ref cntPos); - ser.Sync("enableIntAlarm", ref enableIntAlarm); - ser.Sync("enableIntFlag", ref enableIntFlag); - ser.Sync("enableIntSP", ref enableIntSP); - ser.Sync("enableIntTimer0", ref enableIntTimer[0]); - ser.Sync("enableIntTimer1", ref enableIntTimer[1]); - ser.Sync("intAlarm", ref intAlarm); - ser.Sync("intFlag", ref intFlag); - ser.Sync("intSP", ref intSP); - ser.Sync("intTimer0", ref intTimer[0]); - ser.Sync("intTimer1", ref intTimer[1]); - ser.Sync("pinCnt", ref pinCnt); - ser.Sync("pinPC", ref pinPC); - ser.Sync("sr", ref sr); - ser.Sync("timerDelay0", ref timerDelay[0]); - ser.Sync("timerDelay1", ref timerDelay[1]); - ser.Sync("timerInMode0", ref timerInModeInt0); - ser.Sync("timerInMode1", ref timerInModeInt1); - ser.Sync("timerOutMode0", ref timerOutModeInt0); - ser.Sync("timerOutMode1", ref timerOutModeInt1); - ser.Sync("timerPortEnable0", ref timerPortEnable[0]); - ser.Sync("timerPortEnable1", ref timerPortEnable[1]); - ser.Sync("timerPulse0", ref timerPulse[0]); - ser.Sync("timerPulse1", ref timerPulse[1]); - ser.Sync("timerRunMode0", ref timerRunModeInt0); - ser.Sync("timerRunMode1", ref timerRunModeInt1); - ser.Sync("timerSPMode", ref timerSPModeInt); - ser.Sync("tod0", ref tod[0]); - ser.Sync("tod1", ref tod[1]); - ser.Sync("tod2", ref tod[2]); - ser.Sync("tod3", ref tod[3]); - ser.Sync("todAlarm0", ref todAlarm[0]); - ser.Sync("todAlarm1", ref todAlarm[1]); - ser.Sync("todAlarm2", ref todAlarm[2]); - ser.Sync("todAlarm3", ref todAlarm[3]); - ser.Sync("todAlarmPM", ref todAlarmPM); - ser.Sync("todCounter", ref todCounter); - ser.Sync("todCounterLatch", ref todCounterLatch); - ser.Sync("todIn", ref todIn); - ser.Sync("todPM", ref todPM); - - chipRegion = (Region)chipRegionInt; - timerInMode[0] = (InMode)timerInModeInt0; - timerInMode[1] = (InMode)timerInModeInt1; - timerOutMode[0] = (OutMode)timerOutModeInt0; - timerOutMode[1] = (OutMode)timerOutModeInt1; - timerRunMode[0] = (RunMode)timerRunModeInt0; - timerRunMode[1] = (RunMode)timerRunModeInt1; - timerSPMode = (SPMode)timerSPModeInt; + Sync.SyncObject(ser, this); } public void Write(int addr, byte val) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6567.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6567.cs index 3cbaf24d89..39feeada28 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6567.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6567.cs @@ -3,7 +3,7 @@ // vic ntsc public class MOS6567 : Vic { - static int[][] pipeline = new int[5][]; + static protected int[][] pipeline = new int[5][]; public MOS6567() : base(65, 263, pipeline, 14318181 / 14) diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6569.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6569.cs index 044d199dc1..e648fe349f 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6569.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6569.cs @@ -3,7 +3,7 @@ // vic pal public class MOS6569 : Vic { - static int[][] pipeline = new int[][] + static protected int[][] pipeline = new int[][] { new int[] // xposition { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs index f13fcd2404..0f18e544f1 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOS6581.cs @@ -3,7 +3,7 @@ // sid public class MOS6581 : Sid { - static int[][] waveTable = new int[][] + static protected int[][] waveTable = new int[][] { new int[] { 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs index e065dca408..312be2ca8e 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/MOSPLA.cs @@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - private enum PLABank + protected enum PLABank { None, RAM, @@ -86,35 +86,35 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ------------------------------------ - bool p0; - bool p1; - bool p2; - bool p3; - bool p4; - bool p5; - bool p9; - bool p11; - bool p13; - bool p15; - bool p17; - bool p19; - bool p20; - bool p21; - bool p22; - bool p24; - bool p25; - bool p26; - bool p27; - bool p28; - bool loram; - bool hiram; - bool game; - bool exrom; - bool charen; - bool a15; - bool a14; - bool a13; - bool a12; + protected bool p0; + protected bool p1; + protected bool p2; + protected bool p3; + protected bool p4; + protected bool p5; + protected bool p9; + protected bool p11; + protected bool p13; + protected bool p15; + protected bool p17; + protected bool p19; + protected bool p20; + protected bool p21; + protected bool p22; + protected bool p24; + protected bool p25; + protected bool p26; + protected bool p27; + protected bool p28; + protected bool loram; + protected bool hiram; + protected bool game; + protected bool exrom; + protected bool charen; + protected bool a15; + protected bool a14; + protected bool a13; + protected bool a12; private PLABank Bank(int addr, bool read) { @@ -387,6 +387,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS return 0xFF; } + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } + public byte VicRead(int addr) { game = ReadGame(); diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs index c9db14bbd0..c9014039e9 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Port.cs @@ -35,6 +35,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { return (byte)((Latch & Direction) | (Direction ^ 0xFF)); } + + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } } public class LatchedBooleanPort @@ -70,5 +75,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { return (Latch || !Direction); } + + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs index fd95de24a2..b410b7a2ab 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/SerialPort.cs @@ -19,6 +19,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { } + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } + public bool WriteClockIn() { return true; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs index d6ec1990ba..28170cf655 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Sid.cs @@ -6,27 +6,27 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { // ------------------------------------ - private class Envelope + protected class Envelope { - private const int stateAttack = 0; - private const int stateDecay = 1; - private const int stateRelease = 2; + protected const int stateAttack = 0; + protected const int stateDecay = 1; + protected const int stateRelease = 2; - private int attack; - private int decay; - private bool delay; - private int envCounter; - private int expCounter; - private int expPeriod; - private bool freeze; - private int lfsr; - private bool gate; - private int rate; - private int release; - private int state; - private int sustain; + protected int attack; + protected int decay; + protected bool delay; + protected int envCounter; + protected int expCounter; + protected int expPeriod; + protected bool freeze; + protected int lfsr; + protected bool gate; + protected int rate; + protected int release; + protected int state; + protected int sustain; - private static int[] adsrTable = new int[] + protected static int[] adsrTable = new int[] { 0x7F00, 0x0006, 0x003C, 0x0330, 0x20C0, 0x6755, 0x3800, 0x500E, @@ -34,17 +34,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS 0x3840, 0x77E2, 0x7625, 0x0A93 }; - private static int[] expCounterTable = new int[] + protected static int[] expCounterTable = new int[] { 0xFF, 0x5D, 0x36, 0x1A, 0x0E, 0x06, 0x00 }; - private static int[] expPeriodTable = new int[] + protected static int[] expPeriodTable = new int[] { 0x01, 0x02, 0x04, 0x08, 0x10, 0x1E, 0x01 }; - private static int[] sustainTable = new int[] + protected static int[] sustainTable = new int[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF @@ -241,52 +241,40 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - ser.Sync("attack", ref attack); - ser.Sync("decay", ref decay); - ser.Sync("delay", ref delay); - ser.Sync("envCounter", ref envCounter); - ser.Sync("expCounter", ref expCounter); - ser.Sync("expPeriod", ref expPeriod); - ser.Sync("freeze", ref freeze); - ser.Sync("lfsr", ref lfsr); - ser.Sync("gate", ref gate); - ser.Sync("rate", ref rate); - ser.Sync("release", ref release); - ser.Sync("state", ref state); - ser.Sync("sustain", ref sustain); - } + Sync.SyncObject(ser, this); + } // ------------------------------------ } - private class Voice + protected class Voice { - private int accBits; - private int accNext; - private int accumulator; - private bool controlTestPrev; - private int controlWavePrev; - private int delay; - private int floatOutputTTL; - private int frequency; - private bool msbRising; - private int noise; - private int noNoise; - private int noNoiseOrNoise; - private int noPulse; - private int output; - private int pulse; - private int pulseWidth; - private bool ringMod; - private int ringMsbMask; - private int shiftRegister; - private int shiftRegisterReset; - private bool sync; - private bool test; - private int[] wave; - private int waveform; - private int waveformIndex; - private int[][] waveTable; + protected int accBits; + protected int accNext; + protected int accumulator; + protected bool controlTestPrev; + protected int controlWavePrev; + protected int delay; + protected int floatOutputTTL; + protected int frequency; + protected bool msbRising; + protected int noise; + protected int noNoise; + protected int noNoiseOrNoise; + protected int noPulse; + protected int output; + protected int pulse; + protected int pulseWidth; + protected bool ringMod; + protected int ringMsbMask; + protected int shiftRegister; + protected int shiftRegisterReset; + protected bool sync; + protected bool test; + protected int[] wave; + protected int waveform; + protected int waveformIndex; + protected int[][] waveTable; public Voice(int[][] newWaveTable) { @@ -585,25 +573,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { - ser.Sync("accumulator", ref accumulator); - ser.Sync("delay", ref delay); - ser.Sync("floatOutputTTL", ref floatOutputTTL); - ser.Sync("frequency", ref frequency); - ser.Sync("msbRising", ref msbRising); - ser.Sync("noise", ref noise); - ser.Sync("noNoise", ref noNoise); - ser.Sync("noNoiseOrNoise", ref noNoiseOrNoise); - ser.Sync("noPulse", ref noPulse); - ser.Sync("output", ref output); - ser.Sync("pulse", ref pulse); - ser.Sync("pulseWidth", ref pulseWidth); - ser.Sync("ringMod", ref ringMod); - ser.Sync("ringMsbMask", ref ringMsbMask); - ser.Sync("shiftRegister", ref shiftRegister); - ser.Sync("shiftRegisterReset", ref shiftRegisterReset); - ser.Sync("sync", ref sync); - ser.Sync("test", ref test); - ser.Sync("waveform", ref waveform); + BizHawk.Emulation.Computers.Commodore64.Sync.SyncObject(ser, this); if (ser.IsReader) wave = waveTable[waveform]; @@ -614,28 +584,28 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public Sound.Utilities.SpeexResampler resampler; - private static int[] syncNextTable = new int[] { 1, 2, 0 }; - private static int[] syncPrevTable = new int[] { 2, 0, 1 }; + protected static int[] syncNextTable = new int[] { 1, 2, 0 }; + protected static int[] syncPrevTable = new int[] { 2, 0, 1 }; - private int cachedCycles; - private bool disableVoice3; - private int[] envelopeOutput; - private Envelope[] envelopes; - private bool[] filterEnable; - private int filterFrequency; - private int filterResonance; - private bool filterSelectBandPass; - private bool filterSelectLoPass; - private bool filterSelectHiPass; - private int mixer; - private int potCounter; - private int potX; - private int potY; - private short sample; - private int[] voiceOutput; - private Voice[] voices; - private int volume; - private int[][] waveformTable; + protected int cachedCycles; + protected bool disableVoice3; + protected int[] envelopeOutput; + protected Envelope[] envelopes; + protected bool[] filterEnable; + protected int filterFrequency; + protected int filterResonance; + protected bool filterSelectBandPass; + protected bool filterSelectLoPass; + protected bool filterSelectHiPass; + protected int mixer; + protected int potCounter; + protected int potX; + protected int potY; + protected short sample; + protected int[] voiceOutput; + protected Voice[] voices; + protected int volume; + protected int[][] waveformTable; public Func ReadPotX; public Func ReadPotY; @@ -954,9 +924,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS // ---------------------------------- - public void SyncState(Serializer ser) + public void SyncState(Serializer ser) { - ser.BeginSection("env0"); + Sync.SyncObject(ser, this); + ser.BeginSection("env0"); envelopes[0].SyncState(ser); ser.EndSection(); ser.BeginSection("wav0"); @@ -974,25 +945,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS ser.BeginSection("wav2"); voices[2].SyncState(ser); ser.EndSection(); - ser.Sync("disableVoice3", ref disableVoice3); - ser.Sync("envelopeOutput0", ref envelopeOutput[0]); - ser.Sync("envelopeOutput1", ref envelopeOutput[1]); - ser.Sync("envelopeOutput2", ref envelopeOutput[2]); - ser.Sync("filterEnable0", ref filterEnable[0]); - ser.Sync("filterEnable1", ref filterEnable[1]); - ser.Sync("filterEnable2", ref filterEnable[2]); - ser.Sync("filterFrequency", ref filterFrequency); - ser.Sync("filterResonance", ref filterResonance); - ser.Sync("filterSelectBandPass", ref filterSelectBandPass); - ser.Sync("filterSelectLoPass", ref filterSelectLoPass); - ser.Sync("filterSelectHiPass", ref filterSelectHiPass); - ser.Sync("potCounter", ref potCounter); - ser.Sync("potX", ref potX); - ser.Sync("potY", ref potY); - ser.Sync("voiceOutput0", ref voiceOutput[0]); - ser.Sync("voiceOutput1", ref voiceOutput[1]); - ser.Sync("voiceOutput2", ref voiceOutput[2]); - ser.Sync("volume", ref volume); } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs index c300b47a8f..b472312baf 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Timer.cs @@ -88,18 +88,5 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS } public bool ReadIRQBuffer() { return pinIRQ; } - - protected void SyncInternal(Serializer ser) - { - ser.Sync("pinIRQ", ref pinIRQ); - ser.Sync("timer0", ref timer[0]); - ser.Sync("timer1", ref timer[1]); - ser.Sync("timerLatch0", ref timerLatch[0]); - ser.Sync("timerLatch1", ref timerLatch[1]); - ser.Sync("timerOn0", ref timerOn[0]); - ser.Sync("timerOn1", ref timerOn[1]); - ser.Sync("underflow0", ref underflow[0]); - ser.Sync("underflow1", ref underflow[1]); - } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs index eef95a5af6..4cc2439f9d 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/UserPort.cs @@ -63,5 +63,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { return true; } + + public void SyncState(Serializer ser) + { + Sync.SyncObject(ser, this); + } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Parse.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Parse.cs index f7a3ddd3e5..c5d4268fae 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Parse.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Parse.cs @@ -22,15 +22,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS protected const int rasterIrqLine0Cycle = 1; protected const int rasterIrqLineXCycle = 0; - private int parseaddr; - private int parsecycleBAsprite0; - private int parsecycleBAsprite1; - private int parsecycleBAsprite2; - private int parsecycleFetchSpriteIndex; - private int parsefetch; - private int parsefetchType; - private int parseba; - private int parseact; + protected int parseaddr; + protected int parsecycleBAsprite0; + protected int parsecycleBAsprite1; + protected int parsecycleBAsprite2; + protected int parsecycleFetchSpriteIndex; + protected int parsefetch; + protected int parsefetchType; + protected int parseba; + protected int parseact; private void ParseCycle() { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Render.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Render.cs index 583459b662..1ff0531618 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Render.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Render.cs @@ -7,15 +7,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { public abstract partial class Vic { - private int ecmPixel; - private int pixel; - private int[] pixelBackgroundBuffer; - private int pixelBackgroundBufferDelay; - private int pixelBackgroundBufferIndex; - private int[] pixelBuffer; - private int pixelBufferDelay; - private int pixelBufferIndex; - private int pixelData; + protected int ecmPixel; + protected int pixel; + protected int[] pixelBackgroundBuffer; + protected int pixelBackgroundBufferDelay; + protected int pixelBackgroundBufferIndex; + protected int[] pixelBuffer; + protected int pixelBufferDelay; + protected int pixelBufferIndex; + protected int pixelData; private void Render() { diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Sprite.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Sprite.cs index 6d25edfb90..e0c83332a6 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Sprite.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.Sprite.cs @@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { public abstract partial class Vic { - private class Sprite + protected class Sprite { public bool collideData; public bool collideSprite; diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.State.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.State.cs index fc80fdbacb..33be190729 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.State.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.State.cs @@ -1,78 +1,79 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; namespace BizHawk.Emulation.Computers.Commodore64.MOS { public abstract partial class Vic { - private int backgroundColor0; - private int backgroundColor1; - private int backgroundColor2; - private int backgroundColor3; - private int baCount; - private bool badline; - private bool badlineEnable; - private int bitmapColumn; - private bool bitmapMode; - private int borderB; - private bool borderCheckLEnable; - private bool borderCheckREnable; - private int borderColor; - private int borderL; - private bool borderOnMain; - private bool borderOnVertical; - private int borderR; - private int borderT; - private int[] bufferC; - private int[] bufferG; - private int cycle; - private int cycleIndex; - private bool columnSelect; - private int dataC; - private int dataG; - private bool debugScreen; - private bool displayEnable; - private int displayIndex; - private int displayC; - private bool enableIntLightPen; - private bool enableIntRaster; - private bool enableIntSpriteCollision; - private bool enableIntSpriteDataCollision; - private bool extraColorMode; - private bool idle; - private bool intLightPen; - private bool intRaster; - private bool intSpriteCollision; - private bool intSpriteDataCollision; - private int lastRasterLine; - private int lightPenX; - private int lightPenY; - private bool multicolorMode; - private bool pinAEC = true; - private bool pinBA = true; - private bool pinIRQ = true; - private int[] pixelDataBuffer; - private int pointerCB; - private int pointerVM; - private int rasterInterruptLine; - private int rasterLine; - private int rasterX; - private int rc; - private int refreshCounter; - private bool renderEnabled; - private bool rowSelect; - private int spriteMulticolor0; - private int spriteMulticolor1; - private Sprite[] sprites; - private int sr; - private int vc; - private int vcbase; - private int vmli; - private int xOffset; - private int xScroll; - private int yScroll; + protected int backgroundColor0; + protected int backgroundColor1; + protected int backgroundColor2; + protected int backgroundColor3; + protected int baCount; + protected bool badline; + protected bool badlineEnable; + protected int bitmapColumn; + protected bool bitmapMode; + protected int borderB; + protected bool borderCheckLEnable; + protected bool borderCheckREnable; + protected int borderColor; + protected int borderL; + protected bool borderOnMain; + protected bool borderOnVertical; + protected int borderR; + protected int borderT; + protected int[] bufferC; + protected int[] bufferG; + protected int cycle; + protected int cycleIndex; + protected bool columnSelect; + protected int dataC; + protected int dataG; + protected bool debugScreen; + protected bool displayEnable; + protected int displayIndex; + protected int displayC; + protected bool enableIntLightPen; + protected bool enableIntRaster; + protected bool enableIntSpriteCollision; + protected bool enableIntSpriteDataCollision; + protected bool extraColorMode; + protected bool idle; + protected bool intLightPen; + protected bool intRaster; + protected bool intSpriteCollision; + protected bool intSpriteDataCollision; + protected int lastRasterLine; + protected int lightPenX; + protected int lightPenY; + protected bool multicolorMode; + protected bool pinAEC = true; + protected bool pinBA = true; + protected bool pinIRQ = true; + protected int[] pixelDataBuffer; + protected int pointerCB; + protected int pointerVM; + protected int rasterInterruptLine; + protected int rasterLine; + protected int rasterX; + protected int rc; + protected int refreshCounter; + protected bool renderEnabled; + protected bool rowSelect; + protected int spriteMulticolor0; + protected int spriteMulticolor1; + protected Sprite[] sprites; + protected int sr; + protected int vc; + protected int vcbase; + protected int vmli; + protected int xOffset; + protected int xScroll; + protected int yScroll; public void HardReset() { @@ -157,6 +158,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public void SyncState(Serializer ser) { + Sync.SyncObject(ser, this); + for (int i = 0; i < 8; i++) + { + ser.BeginSection("sprite" + i.ToString()); + Sync.SyncObject(ser, sprites[i]); + ser.EndSection(); + } } } } diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs index 3968529389..0050b8c3b8 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.VideoProvider.cs @@ -4,16 +4,16 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS { public abstract partial class Vic : IVideoProvider { - private int[] buf; - private int bufHeight; - private int bufLength; - private int bufOffset; - private Point bufPoint; - private Rectangle bufRect; - private int bufWidth; + protected int[] buf; + protected int bufHeight; + protected int bufLength; + protected int bufOffset; + protected Point bufPoint; + protected Rectangle bufRect; + protected int bufWidth; // palette - private int[] palette = + protected int[] palette = { Colors.ARGB(0x00, 0x00, 0x00), Colors.ARGB(0xFF, 0xFF, 0xFF), diff --git a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs index 23cf95621e..e7b75e4859 100644 --- a/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs +++ b/BizHawk.Emulation/Computers/Commodore64/MOS/Vic.cs @@ -12,10 +12,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS public bool ReadBABuffer() { return pinBA; } public bool ReadIRQBuffer() { return pinIRQ; } - private int cyclesPerSec; - private int[][] pipeline; - private int totalCycles; - private int totalLines; + protected int cyclesPerSec; + protected int[][] pipeline; + protected int totalCycles; + protected int totalLines; public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec) { diff --git a/BizHawk.Emulation/Computers/Commodore64/Sync.cs b/BizHawk.Emulation/Computers/Commodore64/Sync.cs new file mode 100644 index 0000000000..24cb3b2102 --- /dev/null +++ b/BizHawk.Emulation/Computers/Commodore64/Sync.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace BizHawk.Emulation.Computers.Commodore64 +{ + static class Sync + { + static public void SyncObject(Serializer ser, object obj) + { + BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; + MemberInfo[] members = obj.GetType().GetMembers(defaultFlags); + + Bit refBit; + Boolean refBool; + Byte refByte; + ByteBuffer refByteBuffer; + Int16 refInt16; + Int32 refInt32; + IntBuffer refIntBuffer; + Int32 refPointX; + Int32 refPointY; + Rectangle refRect; + SByte refSByte; + UInt16 refUInt16; + UInt32 refUInt32; + Int32 refRectHeight; + Int32 refRectWidth; + + foreach (MemberInfo member in members) + { + object currentValue = null; + bool fail = false; + FieldInfo fieldInfo = null; + PropertyInfo propInfo = null; + Type valueType = null; + + if (member.MemberType == MemberTypes.Field) + { + fieldInfo = member.ReflectedType.GetField(member.Name, defaultFlags); + valueType = fieldInfo.FieldType; + currentValue = fieldInfo.GetValue(obj); + } + else + { + fail = true; + } + + if (!fail) + { + if (valueType.IsArray) + { + } + + if (currentValue != null) + { + switch (valueType.Name) + { + case "Bit": + refBit = (Bit)currentValue; + ser.Sync(member.Name, ref refBit); + currentValue = refBit; + break; + case "Boolean": + refBool = (Boolean)currentValue; + ser.Sync(member.Name, ref refBool); + currentValue = refBool; + break; + case "Byte": + refByte = (Byte)currentValue; + ser.Sync(member.Name, ref refByte); + currentValue = refByte; + break; + case "Byte[]": + refByteBuffer = new ByteBuffer((byte[])currentValue); + ser.Sync(member.Name, ref refByteBuffer); + currentValue = refByteBuffer.arr; + break; + case "ByteBuffer": + refByteBuffer = (ByteBuffer)currentValue; + ser.Sync(member.Name, ref refByteBuffer); + currentValue = refByteBuffer; + break; + case "Int16": + refInt16 = (Int16)currentValue; + ser.Sync(member.Name, ref refInt16); + currentValue = refInt16; + break; + case "Int32": + refInt32 = (Int32)currentValue; + ser.Sync(member.Name, ref refInt32); + currentValue = refInt32; + break; + case "Int32[]": + refIntBuffer = new IntBuffer((int[])currentValue); + ser.Sync(member.Name, ref refIntBuffer); + currentValue = refIntBuffer.arr; + break; + case "IntBuffer": + refIntBuffer = (IntBuffer)currentValue; + ser.Sync(member.Name, ref refIntBuffer); + currentValue = refIntBuffer; + break; + case "Point": + refPointX = ((Point)currentValue).X; + refPointY = ((Point)currentValue).Y; + ser.Sync(member.Name + "_X", ref refPointX); + ser.Sync(member.Name + "_Y", ref refPointY); + currentValue = new Point(refPointX, refPointY); + break; + case "Rectangle": + refPointX = ((Rectangle)currentValue).X; + refPointY = ((Rectangle)currentValue).Y; + refRectWidth = ((Rectangle)currentValue).Width; + refRectHeight = ((Rectangle)currentValue).Height; + ser.Sync(member.Name + "_X", ref refPointX); + ser.Sync(member.Name + "_Y", ref refPointY); + ser.Sync(member.Name + "_Height", ref refRectHeight); + ser.Sync(member.Name + "_Width", ref refRectWidth); + currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight); + break; + case "SByte": + refSByte = (SByte)currentValue; + ser.Sync(member.Name, ref refSByte); + currentValue = refSByte; + break; + case "UInt16": + refUInt16 = (UInt16)currentValue; + ser.Sync(member.Name, ref refUInt16); + currentValue = refUInt16; + break; + case "UInt32": + refUInt32 = (UInt32)currentValue; + ser.Sync(member.Name, ref refUInt32); + currentValue = refUInt32; + break; + default: + fail = true; + break; + } + } + + if (member.MemberType == MemberTypes.Property) + { + if (propInfo.CanWrite && !fail) + { + MethodInfo setMethod = propInfo.GetSetMethod(); + setMethod.Invoke(obj, new object[] { currentValue }); + } + } + + if (member.MemberType == MemberTypes.Field) + { + fieldInfo.SetValue(obj, currentValue); + } + } + } + } + } +}