コード例 #1
0
ファイル: M35fd.cs プロジェクト: MSylvia/Ketchup
        private IEnumerator TransferCoroutine(ushort sector, ushort address, TransferOpreration operation)
        {
            SetErrorOrState(state: StateCode.Busy);

            var targetTrack     = TrackForSector(sector);
            var trackDifference = Math.Abs(targetTrack - _currentTrack);

            if (trackDifference != 0)
            {
                yield return(new WaitForSeconds(trackDifference * TracksPerSecond));
            }

            if (TransferOkToContinue(sector))
            {
                _currentTrack = targetTrack;

                yield return(new WaitForSeconds(SecondsPerSector));

                if (TransferOkToContinue(sector))
                {
                    ushort[] source, destination;
                    int      sourceIndex, destinationIndex;

                    switch (operation)
                    {
                    case TransferOpreration.Read:
                        source           = _disk.GetSector(sector);
                        sourceIndex      = 0;
                        destination      = _dcpu16.Memory;
                        destinationIndex = address;
                        break;

                    case TransferOpreration.Write:
                        source           = _dcpu16.Memory;
                        sourceIndex      = address;
                        destination      = _disk.GetSector(sector);
                        destinationIndex = 0;
                        break;

                    default:
                        throw new Exception(String.Format("Unexpected operation: {0}.", operation));
                    }

                    Array.Copy(source, sourceIndex, destination, destinationIndex, WordsPerSector);
                }
            }

            if (_currentStateCode == StateCode.Busy)
            {
                SetErrorOrState(state: _disk.IsWriteProtected?StateCode.ReadyWp: StateCode.Ready);
            }

            yield return(null);
        }
コード例 #2
0
ファイル: M35fd.cs プロジェクト: MSylvia/Ketchup
        private IEnumerator TransferCoroutine(ushort sector, ushort address, TransferOpreration operation)
        {
            SetErrorOrState(state: StateCode.Busy);

            var targetTrack = TrackForSector(sector);
            var trackDifference = Math.Abs(targetTrack - _currentTrack);

            if (trackDifference != 0)
            {
                yield return new WaitForSeconds(trackDifference * TracksPerSecond);
            }

            if (TransferOkToContinue(sector))
            {
                _currentTrack = targetTrack;

                yield return new WaitForSeconds(SecondsPerSector);

                if (TransferOkToContinue(sector))
                {
                    ushort[] source, destination;
                    int sourceIndex, destinationIndex;

                    switch (operation)
                    {
                        case TransferOpreration.Read:
                            source = _disk.GetSector(sector);
                            sourceIndex = 0;
                            destination = _dcpu16.Memory;
                            destinationIndex = address;
                            break;
                        case TransferOpreration.Write:
                            source = _dcpu16.Memory;
                            sourceIndex = address;
                            destination = _disk.GetSector(sector);
                            destinationIndex = 0;
                            break;
                        default:
                            throw new Exception(String.Format("Unexpected operation: {0}.", operation));
                    }

                    Array.Copy(source, sourceIndex, destination, destinationIndex, WordsPerSector);
                }
            }

            if (_currentStateCode == StateCode.Busy)
            {
                SetErrorOrState(state: _disk.IsWriteProtected ? StateCode.ReadyWp : StateCode.Ready);
            }

            yield return null;
        }