static void _Main(string[] args) { var deviceWasConnected = false; usb = new UsbHost(new CH376UsbHostHardware(UsbServiceProvider.GetCH376Ports("90.173.150.35", 1288))); do { var devInfo = usb.GetConnectedDeviceInfo(1); if (devInfo != null && !deviceWasConnected) { deviceWasConnected = true; Console.WriteLine("Connected!"); PrintDeviceInfo(1); PrintFddInfo(usb, 1); } else if (devInfo == null && deviceWasConnected) { deviceWasConnected = false; Console.WriteLine("Disconnected..."); } Thread.Sleep(100); usb.UpdateDeviceConnectionStatus(); } while (!Console.KeyAvailable); }
public RookieDriveFddPlugin(PluginContext context, IDictionary <string, object> pluginConfig) { kernelRoutines = new Dictionary <ushort, Action> { { 0x4010, DSKIO }, { 0x4013, () => DSKCHG_GETDPB(true) }, { 0x4016, () => DSKCHG_GETDPB(false) }, { 0x4019, CHOICE }, { 0x401C, DSKFMT }, { 0x401F, MTOFF } }; addressOfCallInihrd = pluginConfig.GetValueOrDefault <ushort>("addressOfCallInihrd", 0x176F); addressOfCallDrives = pluginConfig.GetValueOrDefault <ushort>("addressOfCallDrives", 0x1850); this.slotNumber = new SlotNumber(pluginConfig.GetValue <byte>("NestorMSX.slotNumber")); this.kernelFilePath = pluginConfig.GetMachineFilePath(pluginConfig.GetValueOrDefault("kernelFile", "MsxDosKernel.rom")); this.z80 = context.Cpu; this.memory = context.SlotsSystem; z80.BeforeInstructionFetch += (sender, args) => BeforeZ80InstructionFetch(z80.Registers.PC); this.kernelContents = File.ReadAllBytes(kernelFilePath); ValidateKernelFileContents(kernelContents); host = new UsbHost(new CH376UsbHostHardware(UsbServiceProvider.GetCH376Ports())); UpdateCbiInstance(); }
public static byte[] ExecuteControlInTransfer(this IUsbHost usbHost, UsbSetupPacket setupPacket, int deviceAddress, int endpointNumber = 0) { var dataBuffer = new byte[setupPacket.wLength]; var result = usbHost.ExecuteControlTransfer(setupPacket, dataBuffer, 0, deviceAddress, endpointNumber); if (result.IsError) { throw new UsbTransferException(result.TransactionResult); } return(dataBuffer.Take(result.TransferredDataCount).ToArray()); }
public UsbCbiTransport(IUsbHost host, int deviceAddress) { var device = host.GetConnectedDeviceInfo((byte)deviceAddress); if (device == null) { throw new InvalidOperationException($"There's no device connected with address {deviceAddress}"); } //HACK: Detect Konamiman's Traxdata FDD by VID+PID, //since it's a fully compliant CBI+UFI FDD but it identifies itself with class = FFh UsbInterface iface; if (device.VendorId == 0x0644 && device.ProductId == 1) { iface = device.InterfacesForCurrentConfiguration.First(); } else { iface = device.InterfacesForCurrentConfiguration.Where(i => i.Class == 8 && i.Subclass == 4 && i.Protocol == 0) .SingleOrDefault(); } if (iface == null) { throw new InvalidOperationException("The device does not implement mass storage with the CBI transport on any of the interfaces for the current configuration"); } this.deviceAddress = deviceAddress; this.host = host; bulkInEndpoint = iface.Endpoints.Where(e => e.Type == UsbEndpointType.Bulk && e.DataDirection == UsbDataDirection.IN).First(); bulkOutEndpoint = iface.Endpoints.Where(e => e.Type == UsbEndpointType.Bulk && e.DataDirection == UsbDataDirection.OUT).First(); interruptEndpoint = iface.Endpoints.Where(e => e.Type == UsbEndpointType.Interrupt).First(); adsc = new UsbSetupPacket(0, 0x21); adsc.wIndexL = iface.InterfaceNumber; }
private static void PrintFddInfo(IUsbHost host, int deviceNumber) { var cbi = new UsbCbiTransport(host, deviceNumber); var modeSenseCommand = new byte[] { 0x5A, //opcode 0, 5, //flexible disk page, 0, 0, 0, 0, 0, 192, //parameter list length 0, 0, 0 }; var cbiResetCommand = new byte[] { 0x1D, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; var readFormatCapacitiesCommand = new byte[] { 0x23, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0 }; var readCommand = new byte[] { 0x28, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }; var read0Command = new byte[] { 0x28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var startCommand = new byte[] { 0x1B, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; var inquiryCommand = new byte[] { 0x12, 0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0 }; var sendDiagnosticCommand = new byte[] { 0x1D, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var testUnitReadyCommand = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; var formatCommand = new byte[] { 0x04, 0x17, 0, 0, 0, 0, 0, 0, 12, //param list length 0, 0, 0 }; var formatData = new byte[] { 0, 0xB0, 0, 8, //2nd = A0 for non single track format 0, 0, 0x0B, 0x40, //sector count (1.44M) //0, 0, 0x05, 0xA0, //sector count (720K) 0, 0, 2, 0 //sector size }; Console.WriteLine($"\r\nDevice: {GetInquiryData(cbi, 1)}"); //ExecuteUfiCommand(cbi, 1, modeSenseCommand, "Mode Sense", 192); while (true) { Console.WriteLine(); var key = Console.ReadKey(); if (key.Key == ConsoleKey.F) { ExecuteUfiCommand(cbi, 1, readFormatCapacitiesCommand, "Read format capacities", 100); } else if (key.Key == ConsoleKey.M) { ExecuteUfiCommand(cbi, 1, modeSenseCommand, "Mode sense", 192); } else if (key.Key == ConsoleKey.D) { ExecuteUfiCommand(cbi, 1, sendDiagnosticCommand, "Send diagnostic", 192); } else if (key.Key == ConsoleKey.U) { ExecuteUfiCommand(cbi, 1, testUnitReadyCommand, "Test unit ready", 0); } else if (key.Key == ConsoleKey.X) { for (var side = 0; side < 2; side++) { for (var track = 0; track < 80; track++) { Console.WriteLine($"Format: track {track}, side {side}"); formatCommand[2] = (byte)track; formatData[5] = (byte)((formatData[5] & 0xFE) | side); ExecuteUfiCommand(cbi, 1, formatCommand, "Format", formatData); } } } else { ExecuteUfiCommand(cbi, 1, readCommand, "Read", 512); } } }
static void _Main(string[] args) { var hw = new CH376UsbHostHardware(UsbServiceProvider.GetCH376Ports()); hw.HardwareReset(); var diskName = hw.InitDisk(); if (diskName[0] == '*') { Console.WriteLine(diskName); return; } else { Console.WriteLine("Storage device detected: " + diskName); } dynamic diskTypeAndCapacity = hw.GetDiskTypeAndCapacity(); Console.WriteLine($"Total size: {diskTypeAndCapacity.totalSizeMb} MB"); Console.WriteLine($"Free size: {diskTypeAndCapacity.freeSizeMb} MB"); Console.WriteLine($"Filesystem: {diskTypeAndCapacity.filesystem}"); Console.WriteLine(); string[] files; hw.InitFilesystem(); files = hw.EnumerateFiles("/"); if (files.Length == 0) { Console.WriteLine("*** No files found"); } else { Console.WriteLine("Files found:"); foreach (var name in files) { Console.WriteLine(name); } Console.WriteLine(); } Console.WriteLine("Files found in DSK:"); files = hw.EnumerateFiles("/DSK"); foreach (var name in files) { Console.WriteLine(name); } Console.WriteLine("Writing file... " + hw.WriteFileContents("NBASICX.TXT", longString)); Console.WriteLine(); Console.WriteLine(); if (!hw.ChangeDir("/DSK")) { Console.WriteLine("*** Can't change to dir DSK"); } else { Console.WriteLine("Contents of DSK/NBASIC.TXT:"); Console.Write(hw.ReadFileContents("NBASIC.TXT")); } Console.ReadKey(); return; ///// var deviceWasConnected = false; usb = new UsbHost(new CH376UsbHostHardware(UsbServiceProvider.GetCH376Ports("90.173.150.35", 1288))); do { var devInfo = usb.GetConnectedDeviceInfo(1); if (devInfo != null && !deviceWasConnected) { deviceWasConnected = true; Console.WriteLine("Connected!"); PrintDeviceInfo(1); PrintFddInfo(usb, 1); } else if (devInfo == null && deviceWasConnected) { deviceWasConnected = false; Console.WriteLine("Disconnected..."); } Thread.Sleep(100); usb.UpdateDeviceConnectionStatus(); } while (!Console.KeyAvailable); }