private static object GetInquiryData(UsbCbiTransport cbi, int deviceAddress) { var inquiryCommand = new byte[] { 0x12, 0, 0, 0, 36, 0, 0, 0, 0, 0, 0, 0 }; var inquiryDataBuffer = new byte[36]; while (true) { var result = cbi.ExecuteCommand(inquiryCommand, inquiryDataBuffer, 0, 36, UsbDataDirection.IN); if (result.SenseData[0] == 0x28 || result.SenseData[0] == 0x29) { continue; } if (result.IsError || result.SenseData[0] != 0) { return($"(error: {result.TransactionResult} - {result.SenseData[0]:X}h when getting inquiry data)"); } break; } string GetString(int index, int length) => Encoding.ASCII.GetString(inquiryDataBuffer, index, length).Trim(); return($"{GetString(8, 6)} {GetString(16, 16)} {GetString(32, 4)}"); }
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); } } }