private UsbPacketResult DoFileOpen(string name)
        {
            FixSetFilename();
            ch.WriteCommand(CMD_SET_FILE_NAME);
            ch.WriteMultipleData(Encoding.ASCII.GetBytes(name + "\0"));

            if (name[0] == '/')
            {
                ch.WriteCommand(CMD_WRITE_VAR32);
                ch.WriteData(0x64); //VAR_CURRENT_CLUST
                ch.WriteData(0);
                ch.WriteData(0);
                ch.WriteData(0);
                ch.WriteData(0);
            }

            ch.WriteCommand(CMD_FILE_OPEN);
            return(WaitAndGetResult());
        }
Example #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;
                }
            }
        }