/// <summary>
        /// Write a DragonDos file to a Dragon virtual tape in the CAS format.  If the CAS file already exists, write the
        /// file to the end of the virtual tape.
        /// </summary>
        /// <param name="file">DragonDos file.</param>
        /// <param name="tapeFilename">Name of the CAS file.</param>
        /// <param name="ai">Additional arguments: Optional name of file within virtual tape container.</param>
        private void SaveToCasFile(DragonDosFile file, string tapeFilename, IEnumerator<string> ai)
        {
            var localFilename = ai.MoveNext() ? ai.Current : file.FileInfo.Name;

            IFile dragonFile;
            switch (file.FileType)
            {
                case DragonDosFileType.MachineCode:
                    dragonFile = DragonFile.CreateMachineCodeFile(localFilename, file.GetData(), file.LoadAddress, file.StartAddress, false, false);
                    break;
                case DragonDosFileType.Basic:
                    if (ascii)
                    {
                        var basicTokenizer = new DragonBasicTokenizer(DragonBasicDialect.DragonDos);
                        var basicText = basicTokenizer.DecodeToBytes(file.GetData());
                        dragonFile = DragonFile.CreateBasicFile(localFilename, basicText, true, true);
                    }
                    else
                        dragonFile = DragonFile.CreateBasicFile(localFilename, file.GetData(), false, false);
                    break;
                default:
                    dragonFile = DragonFile.CreateDataFile(localFilename, file.GetData(), false, false);
                    break;
            }

            using (var tape = new DragonTape(new CasTape(new FileStream(tapeFilename, FileMode.Append))))
            {
                tape.WriteFile(dragonFile);
            }
        }
        /// <summary>
        /// Read a file from a virtual Dragon cassette and return the corresponding DragonDosFile
        /// object.
        /// </summary>
        /// <param name="tapeFilename">Name of the virtual Dragon tape.</param>
        /// <param name="ai">Additional parameters: Filename</param>
        /// <returns></returns>
        private DragonDosFile ReadLocalCasFile(string tapeFilename, IEnumerator<string> ai)
        {
            var filename = ai.MoveNext() ? ai.Current : null;

            using (var tape = new DragonTape(new CasTape(new FileStream(tapeFilename, FileMode.Open))))
            {
                var file = (DragonFile) tape.ReadFile(filename);
                switch (file.FileType)
                {
                    case DragonFileType.Basic:
                        return DragonDosFile.CreateBasicFile(file.GetData());
                    case DragonFileType.MachineCode:
                        return DragonDosFile.CreateMachineCodeFile(file.GetData(), file.LoadAddress, file.StartAddress);
                    case DragonFileType.Data:
                        return DragonDosFile.CreateDataFile(file.GetData());
                    default:
                        throw new InvalidFileTypeException();
                }
            }
        }