private void checkBoxConnSCC_CheckedChanged(object sender, EventArgs e) { if (checkBoxConnSCC.Checked) { switch (Settings.Default.SCC_IF) { case 0: comPortSCC = VsifManager.TryToConnectVSIF(VsifSoundModuleType.MSX_FTDI, (PortId)Settings.Default.SCC_Port, false); if (comPortSCC != null) { enableScc(SCCType.SCC1, SCCSlotNo[comboBoxSccSlot.SelectedIndex]); } break; } checkBoxConnSCC.Checked = comPortSCC != null; comboBoxSCC.Enabled = comPortSCC == null; comboBoxPortSCC.Enabled = comPortSCC == null; comboBoxSccSlot.Enabled = comPortSCC == null; } else { comboBoxSCC.Enabled = true; comboBoxPortSCC.Enabled = true; comboBoxSccSlot.Enabled = true; comPortSCC?.Dispose(); } }
private void checkBoxConnOPNA2_CheckedChanged(object sender, EventArgs e) { if (checkBoxConnOPNA2.Checked) { switch (Settings.Default.OPNA2_IF) { case 0: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.OPNA2_Port, false); break; case 1: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.OPNA2_Port, false); break; case 2: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.OPNA2_Port, false); break; } checkBoxConnOPNA2.Checked = comPortOPNA2 != null; comboBoxOPNA2.Enabled = comPortOPNA2 == null; comboBoxPortYM2612.Enabled = comPortOPNA2 == null; } else { comboBoxOPNA2.Enabled = true; comboBoxPortYM2612.Enabled = true; comPortOPNA2?.Dispose(); } }
private void checkBoxConnOPLL_CheckedChanged(object sender, EventArgs e) { if (checkBoxConnOPLL.Checked) { switch (Settings.Default.OPLL_IF) { case 0: comPortOPLL = VsifManager.TryToConnectVSIF(VsifSoundModuleType.SMS, (PortId)Settings.Default.OPLL_Port, false); break; case 1: comPortOPLL = VsifManager.TryToConnectVSIF(VsifSoundModuleType.MSX_FTDI, (PortId)Settings.Default.OPLL_Port, false); break; } checkBoxConnOPLL.Checked = comPortOPLL != null; comboBoxOPLL.Enabled = comPortOPLL == null; comboBoxPortYm2413.Enabled = comPortOPLL == null; } else { comboBoxOPLL.Enabled = true; comboBoxPortYm2413.Enabled = true; comPortOPLL?.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // マネージド状態を破棄します (マネージド オブジェクト) Stop(); } xgmReader?.Dispose(); // アンマネージド リソース (アンマネージド オブジェクト) を解放し、ファイナライザーをオーバーライドします comPortDCSG?.Dispose(); comPortDCSG = null; comPortOPNA2?.Dispose(); comPortOPNA2 = null; // 大きなフィールドを null に設定します disposedValue = true; } }
private void checkBoxConnDCSG_CheckedChanged(object sender, EventArgs e) { if (checkBoxConnDCSG.Checked) { switch (Settings.Default.DCSG_IF) { case 0: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.DCSG_Port, false); break; case 1: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.DCSG_Port, false); break; case 2: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.SMS, (PortId)Settings.Default.DCSG_Port, false); break; case 3: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.DCSG_Port, false); break; } checkBoxConnDCSG.Checked = comPortDCSG != null; comboBoxDCSG.Enabled = comPortDCSG == null; comboBoxPortSN76489.Enabled = comPortDCSG == null; } else { comboBoxDCSG.Enabled = true; comboBoxPortSN76489.Enabled = true; comPortDCSG?.Dispose(); } }
/// <summary> /// /// </summary> /// <param name="iSoundChipType"></param> /// <param name="clock"></param> /// <returns></returns> public static VsifClient TryToConnectVSIF(VsifSoundModuleType soundModule, PortId comPort, bool shareOnly) { lock (lockObject) { foreach (var c in vsifClients) { if (c.SoundModuleType == soundModule) { if (c.DataWriter.PortName.Equals("COM" + (int)(comPort + 1))) { c.ReferencedCount++; return(c); } if (c.DataWriter.PortName.Equals("FTDI_COM" + (int)comPort)) { c.ReferencedCount++; return(c); } } } if (shareOnly) { return(null); } try { switch (soundModule) { case VsifSoundModuleType.Generic_UART: { SerialPort sp = null; sp = new SerialPort("COM" + ((int)comPort + 1)); sp.WriteTimeout = 100; sp.ReadTimeout = 100; sp.BaudRate = 115200; sp.BaudRate = 1200 * (int)Settings.Default.BitBangWaitAY8910; sp.StopBits = StopBits.One; sp.DataBits = 8; sp.Handshake = Handshake.None; sp.Open(); var client = new VsifClient(soundModule, new PortWriterGenericUart(sp)); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } case VsifSoundModuleType.SMS: { SerialPort sp = null; sp = new SerialPort("COM" + ((int)comPort + 1)); sp.WriteTimeout = 100; sp.ReadTimeout = 100; sp.BaudRate = 115200; sp.StopBits = StopBits.Two; //sp.BaudRate = 57600; //sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DataBits = 8; sp.Handshake = Handshake.None; sp.Open(); var client = new VsifClient(soundModule, new PortWriterGenesis(sp)); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } case VsifSoundModuleType.Genesis: { SerialPort sp = null; sp = new SerialPort("COM" + ((int)comPort + 1)); sp.WriteTimeout = 500; sp.ReadTimeout = 500; //sp.BaudRate = 230400; sp.BaudRate = 163840; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DataBits = 8; sp.Open(); var client = new VsifClient(soundModule, new PortWriterGenesis(sp)); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } case VsifSoundModuleType.Genesis_Low: { SerialPort sp = null; sp = new SerialPort("COM" + ((int)comPort + 1)); sp.WriteTimeout = 500; sp.ReadTimeout = 500; sp.BaudRate = 115200; sp.StopBits = StopBits.One; sp.Parity = Parity.None; sp.DataBits = 8; sp.Open(); var client = new VsifClient(soundModule, new PortWriterGenesis(sp)); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } case VsifSoundModuleType.Genesis_FTDI: { var ftdi = new FTD2XX_NET.FTDI(); var stat = ftdi.OpenByIndex((uint)comPort); if (stat == FTDI.FT_STATUS.FT_OK) { ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET); ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG); ftdi.SetBaudRate(FTDI_BAUDRATE_GEN * FTDI_BAUDRATE_GEN_MUL); ftdi.SetTimeouts(500, 500); ftdi.SetLatency(0); byte ps = 0; ftdi.GetPinStates(ref ps); if ((ps & 0x40) == 0) { uint dummy = 0; ftdi.Write(new byte[] { 0x40 }, 1, ref dummy); } var client = new VsifClient(soundModule, new PortWriterGenesis(ftdi, comPort)); //ftdi.Write(new byte[] { (byte)(((0x07 << 1) & 0xe) | 0) }, 1, ref dummy); //ftdi.Write(new byte[] { (byte)(((0x38 >> 2) & 0xe) | 1) }, 1, ref dummy); //ftdi.Write(new byte[] { (byte)(((0xC0 >> 5) & 0xe) | 0) }, 1, ref dummy); //ftdi.Write(new byte[] { 1 }, 1, ref dummy); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } } break; case VsifSoundModuleType.MSX_FTDI: { var ftdi = new FTD2XX_NET.FTDI(); var stat = ftdi.OpenByIndex((uint)comPort); if (stat == FTDI.FT_STATUS.FT_OK) { ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET); ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG); ftdi.SetBaudRate(FTDI_BAUDRATE_MSX * FTDI_BAUDRATE_MSX_MUL); ftdi.SetTimeouts(500, 500); ftdi.SetLatency(0); //{ // uint dummy = 0x00; // ftdi.Write(new byte[] { (byte)dummy }, 1, ref dummy); //} var client = new VsifClient(soundModule, new PortWriterMsx(ftdi, comPort)); client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } } break; case VsifSoundModuleType.NES_FTDI_INDIRECT: case VsifSoundModuleType.NES_FTDI_DIRECT: { var ftdi = new FTD2XX_NET.FTDI(); var stat = ftdi.OpenByIndex((uint)comPort); if (stat == FTDI.FT_STATUS.FT_OK) { ftdi.SetBitMode(0x00, FTDI.FT_BIT_MODES.FT_BIT_MODE_RESET); ftdi.SetBitMode(0xff, FTDI.FT_BIT_MODES.FT_BIT_MODE_ASYNC_BITBANG); ftdi.SetBaudRate(FTDI_BAUDRATE_NES * FTDI_BAUDRATE_NES_MUL); ftdi.SetTimeouts(500, 500); ftdi.SetLatency(0); byte ps = 0; ftdi.GetPinStates(ref ps); if ((ps & 0x10) == 0x10) { uint dummy = 0; ftdi.Write(new byte[] { 0x00 }, 1, ref dummy); } VsifClient client = null; switch (soundModule) { case VsifSoundModuleType.NES_FTDI_DIRECT: client = new VsifClient(soundModule, new PortWriterNesDirect(ftdi, comPort)); break; case VsifSoundModuleType.NES_FTDI_INDIRECT: client = new VsifClient(soundModule, new PortWriterNesIndirect(ftdi, comPort)); break; } client.Disposed += Client_Disposed; vsifClients.Add(client); return(client); } } break; } //sp.Write(new byte[] { (byte)'M', (byte)'a', (byte)'M', (byte)'i' }, 0, 4); //sp.BaseStream.WriteByte((byte)soundModule); //Thread.Sleep(100); //var ret = sp.BaseStream.ReadByte(); //if (ret == 0x0F) //OK } catch (Exception ex) { if (ex.GetType() == typeof(Exception)) { throw; } else if (ex.GetType() == typeof(SystemException)) { throw; } } return(null); } }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <returns></returns> private bool openVGMFile(string fileName) { //Read size using (FileStream vgmFile = File.Open(fileName, FileMode.Open)) { var fileSize = (uint)vgmFile.Length; xgmReader = new BinaryReader(vgmFile); uint fccHeader; fccHeader = (uint)xgmReader.ReadUInt32(); if (fccHeader != FCC_VGM) { return(false); } for (int i = 0; i < 63; i++) { ushort adr = xgmReader.ReadUInt16(); ushort sz = xgmReader.ReadUInt16(); if (adr == 0xffff && sz == 0x1) { SampleDataTable[i] = new SampleData(this, 0, 0); } else { SampleDataTable[i] = new SampleData(this, (uint)(adr * 256), (uint)(sz * 256)); } } xgmMHead = readXGMHeader(xgmReader); //read dac dacData = xgmReader.ReadBytes(xgmMHead.shtSampleDataBlkSize * 256); uint mlen = xgmReader.ReadUInt32(); if (mlen < 0) { return(false); } //read vgm vgmData = xgmReader.ReadBytes((int)mlen); xgmReader = new BinaryReader(new MemoryStream(vgmData)); switch (Settings.Default.DCSG_IF) { case 0: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.DCSG_Port); break; case 1: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.DCSG_Port); break; case 2: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.SMS, (PortId)Settings.Default.DCSG_Port); break; case 3: comPortDCSG = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.DCSG_Port); break; } switch (Settings.Default.OPNA2_IF) { case 0: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis, (PortId)Settings.Default.OPNA2_Port); break; case 1: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_FTDI, (PortId)Settings.Default.OPNA2_Port); break; case 2: comPortOPNA2 = VsifManager.TryToConnectVSIF(VsifSoundModuleType.Genesis_Low, (PortId)Settings.Default.OPNA2_Port); break; } return(true); } }