public string InitDisk()
        {
            ch.WriteCommand(CMD_TEST_CONNECT);
            byte status;

            do
            {
                status = ch.ReadStatus();
            } while (status == 0);
            var result = (UsbPacketResult)(status & 0x7F); // WaitAndGetResult();

            if (result == UsbPacketResult.NoDeviceConnected)
            {
                return("*** No device connected");
            }

            BusResetAndSetHostWithSofMode();
            ch.WriteCommand(CMD_DISK_MOUNT);
            result = WaitAndGetResult();
            if (result != UsbPacketResult.Ok)
            {
                return("*** No proper storage device connected");
            }

            var data = new byte[36];

            ReadUsbData(data, 0);
            return(Encoding.ASCII.GetString(data.Skip(8).ToArray()));
        }
예제 #2
0
        private void Cpu_MemoryAccess(object sender, MemoryAccessEventArgs e)
        {
            if (e.Address == 0x20)
            {
                if (e.EventType == MemoryAccessEventType.BeforePortRead)
                {
                    e.CancelMemoryAccess = true;
                    if (waitingMultiDataTransferLength)
                    {
                        waitingMultiDataTransferLength = false;
                        e.Value = chPorts.ReadData();
                        multiDataTransferRemaining = e.Value;
                        multiDataTransferPointer   = 0;
                        if (e.Value > 0)
                        {
                            multiDataTransferBuffer = chPorts.ReadMultipleData(multiDataTransferRemaining);
                        }
                    }
                    else if (multiDataTransferRemaining > 0)
                    {
                        e.Value = multiDataTransferBuffer[multiDataTransferPointer];
                        multiDataTransferPointer++;
                        multiDataTransferRemaining--;
                    }
                    else
                    {
                        e.Value = chPorts.ReadData();
                    }
                }
                else if (e.EventType == MemoryAccessEventType.BeforePortWrite)
                {
                    e.CancelMemoryAccess = true;

                    if (waitingMultiDataTransferLength)
                    {
                        waitingMultiDataTransferLength = false;
                        multiDataTransferBuffer        = new byte[e.Value];
                        multiDataTransferPointer       = 0;
                        multiDataTransferRemaining     = e.Value;
                        chPorts.WriteData(e.Value);
                    }
                    else if (multiDataTransferRemaining > 0)
                    {
                        multiDataTransferBuffer[multiDataTransferPointer] = e.Value;
                        multiDataTransferPointer++;
                        multiDataTransferRemaining--;
                        if (multiDataTransferRemaining == 0)
                        {
                            chPorts.WriteMultipleData(multiDataTransferBuffer);
                        }
                    }
                    else
                    {
                        chPorts.WriteData(e.Value);
                    }
                }
            }
            else if (e.Address == 0x21)
            {
                if (e.EventType == MemoryAccessEventType.BeforePortRead)
                {
                    e.CancelMemoryAccess = true;
                    e.Value = chPorts.ReadStatus();
                }
                else if (e.EventType == MemoryAccessEventType.BeforePortWrite)
                {
                    e.CancelMemoryAccess = true;
                    chPorts.WriteCommand(e.Value);

                    if (e.Value == CMD_RD_USB_DATA0 || e.Value == CMD_WR_HOST_DATA)
                    {
                        waitingMultiDataTransferLength = true;
                    }
                }
            }
            else if (e.Address == 0xAA)
            {
                if (e.EventType == MemoryAccessEventType.AfterPortWrite)
                {
                    var wasOn = (aaPortValue & 0x40) == 0;
                    var on    = (e.Value & 0x40) == 0;
                    if (on != wasOn)
                    {
                        Debug.WriteLine("CAPS " + (on ? "ON" : "OFF"));
                    }
                    aaPortValue = e.Value;
                }
                else if (e.EventType == MemoryAccessEventType.AfterPortRead)
                {
                    e.Value = aaPortValue;
                }
            }
        }