Beispiel #1
0
        private MediaType DragDropGetMediaType(TreeNode fileNode)
        {
            // Initialise the media type
            MediaType MediaType = MediaType.UnknownMedia;

            // Determine the mediatype based on the Node tag
            if (fileNode.Tag == null)
            {
                //
            }
            else if (fileNode.Tag.GetType() == typeof(TapeInfo))
            {
                MediaType = MediaType.OricTape;
            }
            else if (fileNode.Tag.GetType() == typeof(OricFileInfo))
            {
                OricFileInfo programInfo = (OricFileInfo)fileNode.Tag;

                if (programInfo.MediaType == MediaType.TapeFile)
                {
                    MediaType = MediaType.TapeFile;
                }
            }

            return(MediaType);
        }
Beispiel #2
0
        public virtual OricProgram LoadFile(String diskName, OricFileInfo oricFileInfo)
        {
            OricProgram oricProgram = new OricProgram();

            oricProgram.New();

            return(oricProgram);
        }
Beispiel #3
0
        // Drag and Drop options
        // 1. Tape to Tape
        // 2. Tape to Disk
        // 3. Disk to Disk
        // 4. Disk to Tape

        private void CopyTapeFilesToTape(TreeNode sourceTreeNode, TreeNode destinationTreeNode)
        {
            // Retrieve details of the destination Tape
            TapeInfo destinationTapeInfo = (TapeInfo)destinationTreeNode.Tag;

            OricTape destinationTape = new OricTape();

            destinationTape.TapeName = destinationTapeInfo.FullName;// Path.Combine(destinationTapeInfo.Folder, destinationTapeInfo.Name);

            // Copy a file from a Tape
            if (sourceTreeNode.Tag.GetType() == typeof(OricFileInfo))
            {
                // Retrieve program information from the source node
                OricFileInfo programInfo = (OricFileInfo)sourceTreeNode.Tag;

                // Load the program contents from the source tape
                OricTape    sourceTape  = new OricTape();
                OricProgram oricProgram = sourceTape.Load(Path.Combine(programInfo.Folder, programInfo.ParentName), programInfo.ProgramName, programInfo.ProgramIndex);

                // Copy file to the end of the destination tape
                destinationTape.SaveFile(oricProgram);
            }
            // Copy a whole Tape
            else if (sourceTreeNode.Tag.GetType() == typeof(TapeInfo))
            {
                // Retrieve information about the source Tape
                TapeInfo sourceTapeInfo = (TapeInfo)sourceTreeNode.Tag;

                OricTape sourceTape = new OricTape();
                sourceTape.TapeName = sourceTapeInfo.FullName;// Path.Combine(sourceTapeInfo.Folder, sourceTapeInfo.Name);

                FileInfo fiTapeFile = new FileInfo(sourceTape.TapeName);

                // Retrieve a catalog of all the programs on the source Tape
                OricFileInfo[] tapeCatalog = sourceTape.Catalog(fiTapeFile);

                foreach (OricFileInfo programInfo in tapeCatalog)
                {
                    // Load the program contents from the source tape
                    OricProgram oricProgram = new OricProgram();
                    oricProgram = sourceTape.Load(Path.Combine(programInfo.Folder, programInfo.ParentName), programInfo.ProgramName, programInfo.ProgramIndex);

                    // Copy file to the end of the destination tape
                    destinationTape.SaveFile(oricProgram);
                }
            }

            // Get full pathname of the updated destination Tape
            FileInfo fiTape = new FileInfo(Path.Combine(Path.GetDirectoryName(destinationTapeInfo.FullName), destinationTreeNode.Text));

            // Remove destination Tape from Tree list
            destinationTreeNode.Remove();

            // Add the updated Tape to the Tree list and display the files in the Tape
            TreeNode newTreeNode = mMainForm.AddTapeToTree(fiTape);

            newTreeNode.Expand();
        }
Beispiel #4
0
        /*public OricFileInfo[] GetDirectory()
         * {
         *  OricFileInfo[] files = null;
         *
         *  switch (dosFormat)
         *  {
         *      case DOSFormats.OricDOS:
         *          {
         *              OricDos oricDisc = new OricDos();
         *              files = oricDisc.ReadDirectory(diskPathname);
         *          }
         *          break;
         *
         *      case DOSFormats.SedOric:
         *          {
         *              SedOric oricDisc = new SedOric();
         *              files = oricDisc.ReadDirectory(diskPathname);
         *          }
         *          break;
         *
         *      default:
         *          files = new OricFileInfo[0];
         *          break;
         *  }
         *
         *  return files;
         * }*/

        public OricFileInfo[] GetDirectory(String filter)
        {
            OricFileInfo fileInfo = new OricFileInfo();

            fileInfo.Name = "DISKNAME";

            OricFileInfo[] fileList = new OricFileInfo[10];

            return(fileList);
        }
Beispiel #5
0
        public ctlDataViewerControl()
        {
            InitializeComponent();

            // Set some defaults for the dataviewer
            dataPreview = new Preview(false);
            dataPreview.ScreenFormat = OricProgram.ProgramFormat.UnknownFile;
            dataPreview.DataLength   = 0;

            ProgramInfo = new OricFileInfo();
            ProgramData = new OricProgram();
        }
Beispiel #6
0
        public DataViewerControl()
        {
            InitializeComponent();

            FileInformation = new Label();

            // Set some defaults for the dataviewer
            dataPreview = new Preview(false);
            dataPreview.m_scrnFormat     = OricProgram.ProgramFormat.UnknownFile;
            dataPreview.m_ui16DataLength = 0;

            ProgramInfo = new OricFileInfo();
            ProgramData = new OricProgram();
        }
        //protected override bool IsInputKey(Keys keyData)
        //{
        //    // Make sure we get arrow keys
        //    switch(keyData)
        //    {
        //        case Keys.Up:
        //        case Keys.Left:
        //        case Keys.Down:
        //        case Keys.Right:
        //            return true;
        //    }

        //    // The rest can be determined by the base class
        //    return base.IsInputKey(keyData);
        //}

        //protected override void OnKeyUp(KeyEventArgs e)
        //{
        //    base.OnKeyDown(e);

        //    //MessageBox.Show("raw key:" + e.KeyCode.ToString(), "debug");
        //    //MessageBox.Show("Keys.KeyCode:" + Keys.KeyCode.ToString(), "debug");
        //    //MessageBox.Show("e.KeyCode:" + e.KeyCode.ToString(), "debug");

        //    switch(Keys.KeyCode & e.KeyCode)
        //    {
        //        case Keys.Up:
        //            if(iScrnRow > 0)
        //                iScrnRow--;
        //            break;

        //        case Keys.Down:
        //            if(iScrnRow < 28)
        //                iScrnRow++;
        //            break;

        //        case Keys.Left:
        //            if(iScrnCol > 0)
        //                iScrnCol--;
        //            break;

        //        case Keys.Right:
        //            if(iScrnCol < 39)
        //                iScrnCol++;
        //            break;
        //    }

        //    NewDrawTextPreview();
        //    pictureBox1.Image = screenImage;
        //}

        public TextScreenEditorForm()
        {
            InitializeComponent();

            m_ui16DataLength   = 0;
            m_ui16StartAddress = 0;

            scrnCol = 0;
            scrnRow = 0;

            cScrnPaper = 0;
            cScrnInk   = 7;

            bScrnUpdated = false;

            // Load the standard character set
            BuildCharSet();

            labelSelectedPaperColour.BackColor = Color.Black;
            labelSelectedPaperColour.Tag       = 0;

            labelSelectedInkColour.BackColor = Color.White;
            labelSelectedInkColour.Tag       = 7;

            radioButtonSingle.Checked = true;
            radioButtonSteady.Checked = true;

            screenImage = new Bitmap(pictureBoxEditor.Width, pictureBoxEditor.Height);

            fileInfo = new OricFileInfo();
            oricDisk = new OricDisk();
            oricTape = new OricTape();

            loadedProgram = new OricProgram();

            bShowGrid          = true;
            bShowAttrIndicator = true;

            m_bFlash = true;

            _ZoomFactor = 2;

            radioButtonColourMode.Checked = true;
            editMode = EditingMode.COLOUR_MODE;
        }
Beispiel #8
0
        public OricFileInfo[] GetFiles()
        {
            OricFileInfo[] files = null;

            switch (dosFormat)
            {
            case OricDisk.DOSFormats.OricDOS:
            {
                OricDos oricDisc = new OricDos();
                files = oricDisc.ReadDirectory(fullName);
            }
            break;

            case OricDisk.DOSFormats.SedOric:
            {
                SedOric oricDisc = new SedOric();
                files = oricDisc.ReadDirectory(fullName);
            }
            break;

            case OricDisk.DOSFormats.StratSed:
            {
                StratSed oricDisc = new StratSed();
                files = oricDisc.ReadDirectory(fullName);
            }
            break;

            case OricDisk.DOSFormats.TDOS:
            {
                FTDos oricDisc = new FTDos();
                files = oricDisc.ReadDirectory(fullName);
            }
            break;

            default:
                files = new OricFileInfo[0];
                break;
            }

            return(files);
        }
Beispiel #9
0
        public ScreenViewerControl()
        {
            InitializeComponent();

            _ZoomFactor = 2;

            oricScreenImage = new ScreenImage();

            screenImageSize   = ScreenImage.ScreenImageSize.IMAGE_SIZE_ENLARGED;
            screenImageFormat = ScreenImage.ScreenImageFormat.IMAGE_FORMAT_UNKNOWN;

            FileInformation = new Label();
            FileHeadings    = new Label();

            ProgramInfo = new OricFileInfo();
            ProgramData = new OricProgram();

            checkBoxPaperAttribute.Checked  = true;
            checkBoxInkAttribute.Checked    = true;
            checkBoxOtherAttributes.Checked = true;

            this.pictureBoxScreenImage.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBoxScreenImage_MouseWheel);
        }
Beispiel #10
0
        private OricExplorer.MediaType DragDropGetMediaType(TreeNode fileNode)
        {
            // Initialise the media type
            OricExplorer.MediaType MediaType = OricExplorer.MediaType.UnknownMedia;

            // Determine the mediatype based on the Node tag
            if (fileNode.Tag.GetType().ToString().Equals("OricExplorer.TapeInfo"))
            {
                MediaType = OricExplorer.MediaType.OricTape;
            }
            else if (fileNode.Tag.GetType().ToString().Equals("OricExplorer.Catalog"))
            {
                OricFileInfo programInfo = new OricFileInfo();
                programInfo = (OricFileInfo)fileNode.Tag;

                if (programInfo.MediaType == OricExplorer.MediaType.TapeFile)
                {
                    MediaType = OricExplorer.MediaType.TapeFile;
                }
            }

            return(MediaType);
        }
Beispiel #11
0
 public virtual OricFileInfo[] ReadDirectory(String diskPathname)
 {
     OricFileInfo[] files = new OricFileInfo[0];
     return(files);
 }
Beispiel #12
0
        private OricFileInfo[] ReadOricDosDirectory()
        {
            OricFileInfo[] diskDirectory = null;

            int noOfFiles = 0;

            System.Text.Encoding enc = System.Text.Encoding.ASCII;

            ArrayList diskCatalog = new ArrayList();

            byte bNextTrack  = Convert.ToByte(0);
            byte bNextSector = Convert.ToByte(4);

            byte bCurrTrack  = bNextTrack;
            byte bCurrSector = bNextSector;

            bool bMoreDirectories = true;

            while (bMoreDirectories)
            {
                byte[] sectorData = base.ReadSector(bNextTrack, bNextSector);

                MemoryStream stm = new MemoryStream(sectorData, 0, sectorData.Length);
                BinaryReader rdr = new BinaryReader(stm);

                byte[] bByteArray = new byte[32];

                bNextTrack  = rdr.ReadByte();
                bNextSector = rdr.ReadByte();

                int iFilesInDir = Convert.ToInt16(rdr.ReadByte());

                noOfFiles += iFilesInDir;

                for (int iLoop = 0; iLoop < 15; iLoop++)
                {
                    OricFileInfo diskFile = new OricFileInfo();
                    diskFile.MediaType = ConstantsAndEnums.MediaType.DiskFile;

                    bByteArray = rdr.ReadBytes(6);

                    if (bByteArray[0] != '\0')
                    {
                        string strFilename = enc.GetString(bByteArray).Trim();

                        if (strFilename.Length > 0)
                        {
                            bByteArray = rdr.ReadBytes(3);
                            string strExtension = enc.GetString(bByteArray).Trim();

                            diskFile.Name      = strFilename;
                            diskFile.Extension = strExtension;

                            if (strExtension.Length > 0)
                            {
                                diskFile.ProgramName = string.Format("{0}.{1}", diskFile.Name, diskFile.Extension);
                            }
                            else
                            {
                                diskFile.ProgramName = diskFile.Name;
                            }

                            diskFile.LengthSectors = rdr.ReadUInt16();

                            diskFile.FirstSector = rdr.ReadByte();
                            diskFile.FirstTrack  = rdr.ReadByte();

                            diskFile.LastSector = rdr.ReadByte();
                            diskFile.LastTrack  = rdr.ReadByte();

                            byte bProtection = rdr.ReadByte();

                            if (bProtection == 0x80)
                            {
                                diskFile.Protection = OricProgram.ProtectionStatus.Protected;
                            }
                            else if (bProtection == 0xC0)
                            {
                                diskFile.Protection = OricProgram.ProtectionStatus.Invisible;
                            }
                            else
                            {
                                diskFile.Protection = OricProgram.ProtectionStatus.Unprotected;
                            }

                            byte[] programData = base.ReadSector(diskFile.FirstTrack, diskFile.FirstSector);

                            MemoryStream stm2 = new MemoryStream(programData, 0, programData.Length);
                            BinaryReader rdr2 = new BinaryReader(stm2);

                            bByteArray = rdr2.ReadBytes(2);

                            byte bLoadable = rdr2.ReadByte();

                            bByteArray = rdr2.ReadBytes(1);

                            if (bLoadable == 0xFF)
                            {
                                diskFile.StartAddress = rdr2.ReadUInt16();
                                diskFile.EndAddress   = rdr2.ReadUInt16();

                                // 0000 = code no T, 0001 = basic, 0002 = basic AUTO, ABCD = code T address
                                ushort ui16ExeAddress = rdr2.ReadUInt16();

                                if (ui16ExeAddress == 0x0000)
                                {
                                    diskFile.ExeAddress = diskFile.StartAddress;
                                    diskFile.Format     = OricProgram.ProgramFormat.BinaryFile;
                                    diskFile.AutoRun    = OricProgram.AutoRunFlag.Disabled;
                                }
                                else if (ui16ExeAddress == 0x0001)
                                {
                                    diskFile.ExeAddress = diskFile.StartAddress;
                                    diskFile.Format     = OricProgram.ProgramFormat.BasicProgram;
                                    diskFile.AutoRun    = OricProgram.AutoRunFlag.Disabled;
                                }
                                else if (ui16ExeAddress == 0x0002)
                                {
                                    diskFile.ExeAddress = diskFile.StartAddress;
                                    diskFile.Format     = OricProgram.ProgramFormat.BasicProgram;
                                    diskFile.AutoRun    = OricProgram.AutoRunFlag.Disabled;
                                }
                                else
                                {
                                    diskFile.ExeAddress = ui16ExeAddress;
                                    diskFile.Format     = OricProgram.ProgramFormat.BinaryFile;
                                    diskFile.AutoRun    = OricProgram.AutoRunFlag.Enabled;
                                }

                                if (diskFile.Format == OricProgram.ProgramFormat.BinaryFile)
                                {
                                    switch (diskFile.StartAddress)
                                    {
                                    case 0xBB80:
                                        diskFile.Format = OricProgram.ProgramFormat.TextScreen;
                                        break;

                                    case 0xBBA8:
                                        diskFile.Format = OricProgram.ProgramFormat.TextScreen;
                                        break;

                                    case 0xA000:
                                        diskFile.Format = OricProgram.ProgramFormat.HiresScreen;
                                        break;

                                    case 0xB500:
                                        diskFile.Format = OricProgram.ProgramFormat.CharacterSet;
                                        break;

                                    default:
                                        diskFile.Format = OricProgram.ProgramFormat.BinaryFile;
                                        break;
                                    }

                                    if (diskFile.StartAddress >= 0xBB80 && diskFile.StartAddress <= 0xBFB8)
                                    {
                                        diskFile.Format = OricProgram.ProgramFormat.TextScreen;
                                    }
                                }
                            }
                            else
                            {
                                // Possibly a datafile? (!OPEN/!PUT)
                                diskFile.StartAddress = 0x0000;
                                diskFile.EndAddress   = Convert.ToUInt16(253 * diskFile.LengthSectors);
                                diskFile.ExeAddress   = 0x0000;
                                diskFile.Format       = OricProgram.ProgramFormat.UnknownFile;
                                diskFile.AutoRun      = OricProgram.AutoRunFlag.Disabled;
                            }

                            diskFile.Folder     = base.diskFolder;
                            diskFile.ParentName = base.diskPathname;

                            diskCatalog.Add(diskFile);
                        }
                    }
                    else
                    {
                        bByteArray = rdr.ReadBytes(10);
                    }
                }

                if (bNextTrack == 0 && bNextSector == 0)
                {
                    bMoreDirectories = false;
                }
                else
                {
                    bCurrTrack  = bNextTrack;
                    bCurrSector = bNextSector;
                }
            }

            diskDirectory = new OricFileInfo[diskCatalog.Count];
            diskCatalog.CopyTo(diskDirectory);

            return(diskDirectory);
        }
Beispiel #13
0
        public override OricProgram LoadFile(string diskName, OricFileInfo oricFileInfo)
        {
            int index            = 0;
            int totalDescriptors = 0;

            Byte dataTrack      = 0;
            Byte dataSector     = 0;
            Byte nextDescTrack  = 0;
            Byte nextDescSector = 1;

            OricProgram loadedProgram = new OricProgram();

            loadedProgram.New();

            String diskPathname = Path.Combine(oricFileInfo.Folder, oricFileInfo.ParentName);

            if (base.LoadDisk(diskPathname))
            {
                Byte[] fileDescriptor = GetFileDescriptor(oricFileInfo.ProgramName);

                loadedProgram.Format      = GetFileFormat(fileDescriptor);
                loadedProgram.ProgramName = oricFileInfo.ProgramName;

                if (loadedProgram.ProgramName.ToUpper().EndsWith(".CHS"))
                {
                    loadedProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                }

                if (loadedProgram.ProgramName.ToUpper().EndsWith(".HRS"))
                {
                    loadedProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                }

                Byte formatFlag = fileDescriptor[0x03];

                if ((formatFlag & 0x01) == 0x01)
                {
                    loadedProgram.AutoRun = OricProgram.AutoRunFlag.Enabled;
                }
                else
                {
                    loadedProgram.AutoRun = OricProgram.AutoRunFlag.Disabled;
                }

                UInt16 sectorsToLoad = (UInt16)(fileDescriptor[0x0A] + (fileDescriptor[0x0B] * 256));

                // Get program header info
                switch (loadedProgram.Format)
                {
                case OricProgram.ProgramFormat.DirectAccessFile:
                    loadedProgram.RecordCount  = (UInt16)(fileDescriptor[0x04] + (fileDescriptor[0x05] * 256));
                    loadedProgram.RecordLength = (UInt16)(fileDescriptor[0x06] + (fileDescriptor[0x07] * 256));

                    loadedProgram.StartAddress = 0x0000;
                    loadedProgram.EndAddress   = (UInt16)(loadedProgram.RecordCount * loadedProgram.RecordLength);
                    break;

                case OricProgram.ProgramFormat.SequentialFile:
                    loadedProgram.RecordCount  = 0;
                    loadedProgram.RecordLength = 0;

                    loadedProgram.StartAddress = 0x0000;
                    loadedProgram.EndAddress   = (UInt16)(sectorsToLoad * fileDescriptor.Length);
                    break;

                default:
                    loadedProgram.RecordCount  = 0;
                    loadedProgram.RecordLength = 0;

                    loadedProgram.StartAddress = (UInt16)(fileDescriptor[0x04] + (fileDescriptor[0x05] * 256));
                    loadedProgram.EndAddress   = (UInt16)(fileDescriptor[0x06] + (fileDescriptor[0x07] * 256));
                    break;
                }

                do
                {
                    System.IO.MemoryStream stm = new System.IO.MemoryStream(fileDescriptor, 0, fileDescriptor.Length);
                    System.IO.BinaryReader rdr = new System.IO.BinaryReader(stm);

                    Byte[] byteArray = new Byte[32];

                    nextDescTrack  = rdr.ReadByte();
                    nextDescSector = rdr.ReadByte();

                    Byte firstDescriptorFlag = rdr.ReadByte();

                    int descriptorIndex = 0;

                    if (firstDescriptorFlag == 0xFF)
                    {
                        byteArray = rdr.ReadBytes(9);

                        dataTrack  = rdr.ReadByte();
                        dataSector = rdr.ReadByte();

                        totalDescriptors = 121;
                    }
                    else
                    {
                        dataTrack  = firstDescriptorFlag;
                        dataSector = rdr.ReadByte();

                        totalDescriptors = 126;
                    }

                    int programLength = (loadedProgram.EndAddress - loadedProgram.StartAddress) + 1;

                    //loadedProgram.m_programData = new Byte[0xFFFF];
                    loadedProgram.m_programData = new Byte[programLength];

                    while (dataSector != 0 && descriptorIndex < totalDescriptors)
                    {
                        Byte[] programData = base.ReadSector(dataTrack, dataSector);

                        System.IO.MemoryStream stm2 = new System.IO.MemoryStream(programData, 0, programData.Length);
                        System.IO.BinaryReader rdr2 = new System.IO.BinaryReader(stm2);

                        Byte tmpByte = 0;

                        for (int loop = 0; loop < programData.Length; loop++)
                        {
                            tmpByte = rdr2.ReadByte();

                            if (index < programLength)
                            {
                                loadedProgram.m_programData[index] = tmpByte;
                            }

                            index++;
                        }

                        if (dataSector != 0)
                        {
                            dataTrack  = rdr.ReadByte();
                            dataSector = rdr.ReadByte();

                            descriptorIndex++;
                        }
                    }

                    if (nextDescSector != 0)
                    {
                        fileDescriptor.Initialize();
                        fileDescriptor = base.ReadSector(nextDescTrack, nextDescSector);
                    }
                } while (nextDescSector != 0);
            }

            return(loadedProgram);
        }
Beispiel #14
0
        private OricFileInfo[] ReadSedOricDirectory()
        {
            OricFileInfo[] diskDirectory = null;

            //int noOfFiles = 0;

            System.Text.Encoding enc = System.Text.Encoding.ASCII;

            ArrayList diskCatalog = new ArrayList();

            Byte bNextTrack  = Convert.ToByte(20);
            Byte bNextSector = Convert.ToByte(4);

            Byte bCurrTrack  = bNextTrack;
            Byte bCurrSector = bNextSector;

            Boolean MoreDirectories = true;

            while (MoreDirectories)
            {
                // Read the first directory sector
                Byte[] directory = base.ReadSector(bCurrTrack, bCurrSector);

                if (directory[0] == 0x00 && directory[1] == 0x00)
                {
                    MoreDirectories = false;
                }
                else
                {
                    bCurrTrack  = directory[0];
                    bCurrSector = directory[1];
                }

                // Scan thru all 15 entries to build the directory
                UInt16 DirectoryIndex = 0;

                System.IO.MemoryStream stm = new System.IO.MemoryStream(directory, 0, 256);
                System.IO.BinaryReader rdr = new System.IO.BinaryReader(stm);
                stm.Seek(0x10, SeekOrigin.Begin);

                do
                {
                    if (rdr.PeekChar() != 0x00)
                    {
                        // Read the filename
                        String Filename = enc.GetString(rdr.ReadBytes(9)).Trim();

                        // Read the file extension
                        String FileExtension = enc.GetString(rdr.ReadBytes(3)).Trim();

                        // Read the file descriptor track
                        Byte FileDescTrack = rdr.ReadByte();

                        // Read the file descriptor sector
                        Byte FileDescSector = rdr.ReadByte();

                        // Read the no. of sectors used by file (includes file descriptor)
                        Byte SectorsUsed = rdr.ReadByte();

                        // Read the files protection status
                        Byte ProtectionStatus = rdr.ReadByte();

                        OricFileInfo diskFileInfo = new OricFileInfo();
                        diskFileInfo.MediaType = OricExplorer.MediaType.DiskFile;

                        //diskFileInfo.m_bDosFormat = OricDisk.DOSFormat.SedOric;

                        diskFileInfo.Folder     = base.diskFolder;
                        diskFileInfo.ParentName = base.diskPathname;

                        diskFileInfo.ProgramName = Filename;
                        diskFileInfo.Extension   = FileExtension;

                        if (FileExtension.Length > 0)
                        {
                            diskFileInfo.ProgramName = String.Format("{0}.{1}", Filename, FileExtension);
                        }
                        else
                        {
                            diskFileInfo.ProgramName = Filename;
                        }

                        diskFileInfo.FirstTrack    = FileDescTrack;
                        diskFileInfo.FirstSector   = FileDescSector;
                        diskFileInfo.LengthSectors = SectorsUsed;

                        if (ProtectionStatus == 0xC0)
                        {
                            diskFileInfo.Protection = OricProgram.ProtectionStatus.Protected;
                        }
                        else if (ProtectionStatus == 0x40)
                        {
                            diskFileInfo.Protection = OricProgram.ProtectionStatus.Unprotected;
                        }
                        else
                        {
                            diskFileInfo.Protection = OricProgram.ProtectionStatus.Unprotected;
                        }

                        Byte[] FileDescriptor = base.ReadSector(FileDescTrack, FileDescSector);

                        System.IO.MemoryStream stmFileDescriptor = new System.IO.MemoryStream(FileDescriptor, 0, FileDescriptor.Length);
                        System.IO.BinaryReader rdrFileDescriptor = new System.IO.BinaryReader(stmFileDescriptor);

                        stmFileDescriptor.Seek(0x03, SeekOrigin.Begin);

                        Byte FileType = rdrFileDescriptor.ReadByte();

                        if ((FileType & 0x08) == 0x08)
                        {
                            // We have a direct access file
                            diskFileInfo.m_ui16NoOfRecords  = rdrFileDescriptor.ReadUInt16();
                            diskFileInfo.m_ui16RecordLength = rdrFileDescriptor.ReadUInt16();

                            diskFileInfo.StartAddress = 0x0000;
                            diskFileInfo.EndAddress   = (ushort)(diskFileInfo.m_ui16NoOfRecords * diskFileInfo.m_ui16RecordLength);
                        }
                        else if ((FileType & 0x10) == 0x10)
                        {
                            // We have a sequential file
                            diskFileInfo.StartAddress = 0x0000;
                            diskFileInfo.EndAddress   = (ushort)((diskFileInfo.LengthSectors - 1) * 256);
                        }
                        else
                        {
                            diskFileInfo.StartAddress = rdrFileDescriptor.ReadUInt16();
                            diskFileInfo.EndAddress   = rdrFileDescriptor.ReadUInt16();
                        }

                        diskFileInfo.ExeAddress = rdrFileDescriptor.ReadUInt16();

                        if ((FileType & 0x08) == 0x08)
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.DirectAccessFile;
                        }
                        else if ((FileType & 0x10) == 0x10)
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.SequentialFile;
                        }
                        else if ((FileType & 0x20) == 0x20)
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.WindowFile;
                        }
                        else if ((FileType & 0x40) == 0x40)
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.CodeFile;
                        }
                        else if ((FileType & 0x80) == 0x80)
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.BasicProgram;
                        }
                        else
                        {
                            diskFileInfo.Format = OricProgram.ProgramFormat.UnknownFile;
                        }

                        if (diskFileInfo.Format == OricProgram.ProgramFormat.CodeFile)
                        {
                            switch (diskFileInfo.StartAddress)
                            {
                            case 0xBB80:
                                if (diskFileInfo.ProgramName.ToUpper().EndsWith(".HLP"))
                                {
                                    diskFileInfo.Format = OricProgram.ProgramFormat.HelpFile;
                                }
                                else
                                {
                                    diskFileInfo.Format = OricProgram.ProgramFormat.TextScreen;
                                }
                                break;

                            case 0xBBA8:
                                if (diskFileInfo.ProgramName.ToUpper().EndsWith(".HLP"))
                                {
                                    diskFileInfo.Format = OricProgram.ProgramFormat.HelpFile;
                                }
                                else
                                {
                                    diskFileInfo.Format = OricProgram.ProgramFormat.TextScreen;
                                }
                                break;

                            case 0xA000: diskFileInfo.Format = OricProgram.ProgramFormat.HiresScreen; break;

                            case 0xB500: diskFileInfo.Format = OricProgram.ProgramFormat.CharacterSet; break;

                            default: diskFileInfo.Format = OricProgram.ProgramFormat.CodeFile; break;
                            }

                            if (diskFileInfo.StartAddress >= 0xA000 && diskFileInfo.StartAddress <= 0xBF3F)
                            {
                                // Possibly a HIRES screen
                                if (diskFileInfo.ProgramName.ToUpper().EndsWith(".HRS"))
                                {
                                    diskFileInfo.Format = OricProgram.ProgramFormat.HiresScreen;
                                }
                            }

                            if (diskFileInfo.ProgramName.ToUpper().EndsWith(".CHS"))
                            {
                                diskFileInfo.Format = OricProgram.ProgramFormat.CharacterSet;
                            }
                        }

                        if ((FileType & 0x01) == 0x01)
                        {
                            diskFileInfo.AutoRun = OricProgram.AutoRunFlag.Enabled;
                        }
                        else
                        {
                            diskFileInfo.AutoRun = OricProgram.AutoRunFlag.Disabled;
                        }

                        diskCatalog.Add(diskFileInfo);
                    }

                    DirectoryIndex++;
                } while (DirectoryIndex < 15);
            }

            diskDirectory = new OricFileInfo[diskCatalog.Count];
            diskCatalog.CopyTo(diskDirectory);

            return(diskDirectory);
        }
Beispiel #15
0
        public OricFileInfo[] Catalog(FileInfo fiFileInfo)
        {
            ushort i16ProgramCount = 0;
            ushort i16NoNameCount  = 1;

            bool bReadError = false;

            // Store the tape name
            TapeName = fiFileInfo.FullName;

            if (fiFileInfo.Name == "NewTape.tap")
            {
                i16NoNameCount  = 1;
                i16ProgramCount = 0;
            }

            // Read the entire tape into a buffer
            ReadTapeIntoBuffer();

            // Create an array to store program information
            ArrayList tapeCatalog = new ArrayList();

            // Initialise the buffer position
            m_ui32BufferIdx = 0;

            // Syncronise with the tape header
            while (SyncTape() && !bReadError)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Check details in Program header are valid
                if (programHeader.ui16StartAddress >= programHeader.ui16EndAddress)
                {
                    if (WriteToLogFile)
                    {
                        swLogfile.WriteLine("> *** Invalid Start/End address found in header. ***");
                        swLogfile.WriteLine("> *** Start : ${0:X4}, End : ${1:X4} ***",
                                            programHeader.ui16StartAddress, programHeader.ui16EndAddress);

                        bReadError = true;

                        m_ui32BufferIdx = (uint)(m_bTapeBuffer.Length + 1);
                    }
                }
                else
                {
                    // Create a Catalog object to store tape information
                    OricFileInfo tapeProgram = new OricFileInfo
                    {
                        Folder = fiFileInfo.DirectoryName,

                        // Set the parent name
                        ParentName = fiFileInfo.Name,

                        // Store program information
                        StartAddress = programHeader.ui16StartAddress,
                        EndAddress   = programHeader.ui16EndAddress,
                        AutoRun      = programHeader.bAutoRun
                    };

                    if (programHeader.bProgramFormat == 0x00)
                    {
                        tapeProgram.Format = OricProgram.ProgramFormat.BasicProgram;
                    }
                    else
                    {
                        if (programHeader.ui16StartAddress == 0xA000)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                        }
                        else if (programHeader.ui16StartAddress == 0xB500)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                        }
                        else if (programHeader.ui16StartAddress.In((ushort)0xBB80, (ushort)0xBBA8))
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.TextScreen;
                        }
                        else
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.BinaryFile;
                        }
                    }

                    if (programHeader.strProgramName == null)
                    {
                        tapeProgram.ProgramName = string.Format("NONAME{0:G3}", i16NoNameCount);
                        i16NoNameCount++;
                    }
                    else
                    {
                        tapeProgram.ProgramName = programHeader.strProgramName;
                    }

                    tapeProgram.MediaType = ConstantsAndEnums.MediaType.TapeFile;

                    tapeProgram.ProgramIndex = i16ProgramCount;
                    i16ProgramCount++;

                    // Add information to the catalog
                    tapeCatalog.Add(tapeProgram);

                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += tapeProgram.LengthBytes;

                    // Skip passed the null terminator
                    m_ui32BufferIdx++;
                }
            }

            OricFileInfo[] programList = new OricFileInfo[tapeCatalog.Count];
            tapeCatalog.CopyTo(programList);

            //foreach (var grp in programList.ToList().GroupBy(g => g.ProgramName))
            //{
            //    int i = 0;
            //    if (grp.Count() > 1)
            //    {
            //        foreach(var itm in grp)
            //        {
            //            itm.ProgramName += $"#{++i}";
            //        }
            //    }
            //}

            return(programList);
        }
Beispiel #16
0
        private OricFileInfo[] ReadFTDosDirectory()
        {
            OricFileInfo[] diskDirectory = null;

            int iDirFileCount = 0;

            UInt16 i16DirectoryIndex = 1;
            UInt16 i16EntryIndex     = 1;

            System.Text.Encoding enc = System.Text.Encoding.ASCII;

            ArrayList diskCatalog = new ArrayList();

            Byte bNextTrack  = 20;
            Byte bNextSector = 2;

            Byte bCurrTrack  = bNextTrack;
            Byte bCurrSector = bNextSector;

            Boolean bMoreDirectories = true;

            while (bMoreDirectories)
            {
                iDirFileCount = 0;

                Byte[] sectorData = base.ReadSector(bNextTrack, bNextSector);

                System.IO.MemoryStream stm = new System.IO.MemoryStream(sectorData, 0, sectorData.Length);
                System.IO.BinaryReader rdr = new System.IO.BinaryReader(stm);

                Byte[] bByteArray = new Byte[32];
                bByteArray = rdr.ReadBytes(2);

                bNextTrack  = rdr.ReadByte();
                bNextSector = rdr.ReadByte();

                for (int iLoop = 0; iLoop < 14; iLoop++)
                {
                    OricFileInfo diskFile = new OricFileInfo();
                    diskFile.MediaType = OricExplorer.MediaType.DiskFile;

                    diskFile.FirstTrack  = rdr.ReadByte();
                    diskFile.FirstSector = rdr.ReadByte();

                    diskFile.Folder     = base.diskFolder;
                    diskFile.ParentName = base.diskPathname;

                    Byte bProtection = rdr.ReadByte();

                    if (bProtection == 'U')
                    {
                        diskFile.Protection = OricProgram.ProtectionStatus.Unlocked;
                    }
                    else if (bProtection == 'L')
                    {
                        diskFile.Protection = OricProgram.ProtectionStatus.Locked;
                    }
                    else
                    {
                        diskFile.Protection = OricProgram.ProtectionStatus.Unlocked;
                    }

                    bByteArray = rdr.ReadBytes(8);

                    if ((bByteArray[0] != 0xFF && bByteArray[0] != 0x00 && bByteArray[0] != 0x6C) && diskFile.FirstTrack != 0xFF)
                    {
                        String strFilename = enc.GetString(bByteArray).Trim();

                        if (strFilename.Length > 0)
                        {
                            // Read decimal point between filename and extension
                            bByteArray = rdr.ReadBytes(1);

                            // Read the Extension
                            bByteArray = rdr.ReadBytes(3);
                            String strExtension = enc.GetString(bByteArray).Trim();

                            diskFile.Name      = strFilename;
                            diskFile.Extension = strExtension;

                            if (strExtension.Length > 0)
                            {
                                diskFile.ProgramName = String.Format("{0}.{1}", diskFile.Name, diskFile.Extension);
                            }
                            else
                            {
                                diskFile.ProgramName = diskFile.Name;
                            }

                            bByteArray = rdr.ReadBytes(1);

                            if (strExtension.Equals("SCR"))
                            {
                                diskFile.Format = OricProgram.ProgramFormat.TextScreen;
                            }
                            else if (strExtension.Equals("BAS"))
                            {
                                diskFile.Format = OricProgram.ProgramFormat.BasicProgram;
                            }
                            else if (strExtension.Equals("CMD") || strExtension.Equals("BIN") || strExtension.Equals("SYS"))
                            {
                                diskFile.Format = OricProgram.ProgramFormat.CodeFile;
                            }
                            else
                            {
                                diskFile.Format = OricProgram.ProgramFormat.UnknownFile;
                            }

                            diskFile.LengthSectors = rdr.ReadByte();

                            bByteArray = rdr.ReadBytes(1);

                            Byte[] fileDesc = base.ReadSector(diskFile.FirstTrack, diskFile.FirstSector);

                            System.IO.MemoryStream stm2 = new System.IO.MemoryStream(fileDesc, 0, sectorData.Length);
                            System.IO.BinaryReader rdr2 = new System.IO.BinaryReader(stm2);

                            bByteArray = rdr2.ReadBytes(2);

                            diskFile.StartAddress = rdr2.ReadUInt16();
                            diskFile.EndAddress   = (ushort)(diskFile.StartAddress + rdr2.ReadUInt16());
                            diskFile.ExeAddress   = 0;
                            diskFile.AutoRun      = OricProgram.AutoRunFlag.Disabled;

                            if ((diskFile.StartAddress == 0x0000 && diskFile.EndAddress == 0x0000) && strExtension != "SYS")
                            {
                                diskFile.Format = OricProgram.ProgramFormat.UnknownFile;
                            }

                            //diskFile.FirstTrack =

                            diskFile.DirectoryIndex = i16DirectoryIndex;
                            diskFile.EntryIndex     = i16EntryIndex;

                            diskCatalog.Add(diskFile);

                            iDirFileCount++;
                        }

                        i16EntryIndex++;
                    }
                    else
                    {
                        bByteArray = rdr.ReadBytes(7);
                        //swOutfile.WriteLine();
                    }
                }

                iDirFileCount = 0;

                if ((bNextTrack == 0xFF && bNextSector == 0) || (bNextTrack == 0x6C && bNextSector == 0x6C) || (bNextTrack == 0x00 && bNextSector == 0x00))
                {
                    bMoreDirectories = false;
                }
                else
                {
                    bCurrTrack  = bNextTrack;
                    bCurrSector = bNextSector;

                    i16EntryIndex = 1;
                    i16DirectoryIndex++;
                }
            }

            diskDirectory = new OricFileInfo[diskCatalog.Count];
            diskCatalog.CopyTo(diskDirectory);

            return(diskDirectory);
        }
Beispiel #17
0
        public override OricProgram LoadFile(string diskName, OricFileInfo oricFileInfo)
        {
            int index            = 0;
            int totalDescriptors = 0;

            byte dataTrack      = 0;
            byte dataSector     = 0;
            byte nextDescTrack  = 0;
            byte nextDescSector = 1;

            OricProgram loadedProgram = new OricProgram();

            loadedProgram.New();

            string diskPathname = Path.Combine(oricFileInfo.Folder, oricFileInfo.ParentName);

            if (base.LoadDisk(diskPathname))
            {
                byte[] fileDescriptor = base.ReadSector(oricFileInfo.FirstTrack, oricFileInfo.FirstSector);

                loadedProgram.Format      = OricProgram.ProgramFormat.BasicProgram; // GetFileFormat(fileDescriptor);
                loadedProgram.ProgramName = oricFileInfo.ProgramName;

                if (loadedProgram.ProgramName.ToUpper().EndsWith(".CHS"))
                {
                    loadedProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                }
                else if (loadedProgram.ProgramName.ToUpper().EndsWith(".HRS"))
                {
                    loadedProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                }
                else if (loadedProgram.ProgramName.ToUpper().EndsWith(".SCR"))
                {
                    loadedProgram.Format = OricProgram.ProgramFormat.TextScreen;
                }

                //byte formatFlag = fileDescriptor[0x03];

                /*if ((formatFlag & 0x01) == 0x01)
                 * {
                 *  loadedProgram.AutoRun = OricProgram.AutoRunFlag.Enabled;
                 * }
                 * else
                 * {
                 *  loadedProgram.AutoRun = OricProgram.AutoRunFlag.Disabled;
                 * }*/

                //ushort sectorsToLoad = (ushort)(fileDescriptor[0x0A] + (fileDescriptor[0x0B] * 256));
                ushort sectorsToLoad = oricFileInfo.LengthSectors;

                // Get program header info
                switch (loadedProgram.Format)
                {
                case OricProgram.ProgramFormat.DirectAccessFile:
                    loadedProgram.RecordCount  = (ushort)(fileDescriptor[0x04] + (fileDescriptor[0x05] * 256));
                    loadedProgram.RecordLength = (ushort)(fileDescriptor[0x06] + (fileDescriptor[0x07] * 256));

                    loadedProgram.StartAddress = 0x0000;
                    loadedProgram.EndAddress   = (ushort)(loadedProgram.RecordCount * loadedProgram.RecordLength);
                    break;

                case OricProgram.ProgramFormat.SequentialFile:
                    loadedProgram.RecordCount  = 0;
                    loadedProgram.RecordLength = 0;

                    loadedProgram.StartAddress = 0x0000;
                    loadedProgram.EndAddress   = (ushort)(sectorsToLoad * fileDescriptor.Length);
                    break;

                default:
                    loadedProgram.RecordCount  = 0;
                    loadedProgram.RecordLength = 0;

                    loadedProgram.StartAddress = (ushort)(fileDescriptor[0x02] + (fileDescriptor[0x03] * 256));
                    loadedProgram.EndAddress   = (ushort)(loadedProgram.StartAddress + ((ushort)(fileDescriptor[0x04] + (fileDescriptor[0x05] * 256))));
                    break;
                }

                do
                {
                    MemoryStream stm = new MemoryStream(fileDescriptor, 0, fileDescriptor.Length);
                    BinaryReader rdr = new BinaryReader(stm);

                    byte[] byteArray = new byte[32];

                    nextDescTrack  = rdr.ReadByte();
                    nextDescSector = rdr.ReadByte();

                    byteArray = rdr.ReadBytes(4);

                    // byte firstDescriptorFlag = rdr.ReadByte();

                    int descriptorIndex = 0;
                    totalDescriptors = 125;

                    dataTrack  = rdr.ReadByte();
                    dataSector = rdr.ReadByte();

                    /*if (firstDescriptorFlag == 0xFF)
                     * {
                     *  byteArray = rdr.ReadBytes(9);
                     *
                     *  dataTrack = rdr.ReadByte();
                     *  dataSector = rdr.ReadByte();
                     *
                     *  totalDescriptors = 121;
                     * }
                     * else
                     * {
                     *  dataTrack = firstDescriptorFlag;
                     *  dataSector = rdr.ReadByte();
                     *
                     *  totalDescriptors = 126;
                     * }*/

                    int programLength = (loadedProgram.EndAddress - loadedProgram.StartAddress) + 1;

                    loadedProgram.m_programData = new byte[programLength];

                    while (dataSector != 0xFF && descriptorIndex < totalDescriptors)
                    {
                        byte[] programData = base.ReadSector(dataTrack, dataSector);

                        MemoryStream stm2 = new MemoryStream(programData, 0, programData.Length);
                        BinaryReader rdr2 = new BinaryReader(stm2);

                        byte tmpByte = 0;

                        int loopStart = 0;

                        if (loadedProgram.Format == OricProgram.ProgramFormat.BasicProgram)
                        {
                            if (descriptorIndex == 0)
                            {
                                // Skip first byte
                                tmpByte   = rdr2.ReadByte();
                                loopStart = 1;
                            }
                        }

                        for (int loop = loopStart; loop < programData.Length; loop++)
                        {
                            tmpByte = rdr2.ReadByte();

                            if (index < programLength)
                            {
                                loadedProgram.m_programData[index] = tmpByte;
                            }

                            index++;
                        }

                        if (dataSector != 0)
                        {
                            dataTrack  = rdr.ReadByte();
                            dataSector = rdr.ReadByte();

                            descriptorIndex++;
                        }
                    }

                    if (nextDescSector != 0)
                    {
                        fileDescriptor.Initialize();
                        fileDescriptor = base.ReadSector(nextDescTrack, nextDescSector);
                    }
                } while (nextDescSector != 0);
            }

            return(loadedProgram);
        }
Beispiel #18
0
        public OricFileInfo[] Catalog(FileInfo fiFileInfo)
        {
            Int16 i16ProgramCount = 0;
            Int16 i16NoNameCount  = 1;

            Boolean bReadError = false;

            // Store the tape name
            TapeName = fiFileInfo.FullName;

            if (fiFileInfo.Name == "NewTape.tap")
            {
                i16NoNameCount  = 1;
                i16ProgramCount = 0;
            }

            // Read the entire tape into a buffer
            ReadTapeIntoBuffer();

            // Create an array to store program information
            ArrayList tapeCatalog = new ArrayList();

            // Initialise the buffer position
            m_ui32BufferIdx = 0;

            // Syncronise with the tape header
            while (SyncTape() && !bReadError)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Check details in Program header are valid
                if (programHeader.ui16StartAddress >= programHeader.ui16EndAddress)
                {
                    if (m_bWriteToLogfile)
                    {
                        swLogfile.WriteLine("> *** Invalid Start/End address found in header. ***");
                        swLogfile.WriteLine("> *** Start : ${0:X4}, End : ${1:X4} ***",
                                            programHeader.ui16StartAddress, programHeader.ui16EndAddress);

                        bReadError = true;

                        m_ui32BufferIdx = (UInt32)(m_bTapeBuffer.Length + 1);
                    }
                }
                else
                {
                    // Create a Catalog object to store tape information
                    OricFileInfo tapeProgram = new OricFileInfo();

                    tapeProgram.Folder = fiFileInfo.DirectoryName;

                    // Set the parent name
                    tapeProgram.ParentName = fiFileInfo.Name;

                    // Store program information
                    tapeProgram.StartAddress = programHeader.ui16StartAddress;
                    tapeProgram.EndAddress   = programHeader.ui16EndAddress;
                    tapeProgram.AutoRun      = programHeader.bAutoRun;

                    if (programHeader.bProgramFormat == 0x00)
                    {
                        tapeProgram.Format = OricProgram.ProgramFormat.BasicProgram;
                    }
                    else
                    {
                        if (programHeader.ui16StartAddress == 0xA000)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.HiresScreen;
                        }
                        else if (programHeader.ui16StartAddress == 0xB500)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CharacterSet;
                        }
                        else if (programHeader.ui16StartAddress == 0xBB80 || programHeader.ui16StartAddress == 0xBBA8)
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.TextScreen;
                        }
                        else
                        {
                            tapeProgram.Format = OricProgram.ProgramFormat.CodeFile;
                        }
                    }

                    if (programHeader.strProgramName == null)
                    {
                        tapeProgram.ProgramName = String.Format("NONAME{0:G3}", i16NoNameCount);
                        i16NoNameCount++;
                    }
                    else
                    {
                        tapeProgram.ProgramName = programHeader.strProgramName;
                    }

                    tapeProgram.MediaType = OricExplorer.MediaType.TapeFile;

                    tapeProgram.ProgramIndex = i16ProgramCount;
                    i16ProgramCount++;

                    // Add information to the catalog
                    tapeCatalog.Add(tapeProgram);

                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += tapeProgram.LengthBytes;

                    // Skip passed the null terminator
                    m_ui32BufferIdx++;
                }
            }

            OricFileInfo[] programList = new OricFileInfo[tapeCatalog.Count];
            tapeCatalog.CopyTo(programList);

            return(programList);
        }
Beispiel #19
0
        public override OricProgram LoadFile(string diskName, OricFileInfo programInfo)
        {
            OricProgram loadProgram = new OricProgram();

            loadProgram.New();

            string diskPathname = Path.Combine(programInfo.Folder, programInfo.ParentName);

            if (base.LoadDisk(diskPathname))
            {
                loadProgram.Format       = programInfo.Format;
                loadProgram.StartAddress = programInfo.StartAddress;
                loadProgram.EndAddress   = programInfo.EndAddress;

                byte bFirstTrack  = programInfo.FirstTrack;
                byte bFirstSector = programInfo.FirstSector;

                string strSectorKey = base.CreateKey(bFirstTrack, bFirstSector);

                // Get sector data
                //byte[] sectorData = new byte[512];
                byte[] sectorData = base.ReadSector(bFirstTrack, bFirstSector);

                MemoryStream stm = new MemoryStream(sectorData, 0, sectorData.Length);
                BinaryReader rdr = new BinaryReader(stm);

                byte[] bByteArray = new byte[32];
                byte   bNoOfBytes = 0;

                byte bNextTrack  = rdr.ReadByte();
                byte bNextSector = rdr.ReadByte();

                if (programInfo.Format == OricProgram.ProgramFormat.UnknownFile)
                {
                    bByteArray = rdr.ReadBytes(1);
                    bNoOfBytes = 0xFD;  // 253 bytes
                }
                else
                {
                    bByteArray = rdr.ReadBytes(8);
                    bNoOfBytes = rdr.ReadByte();
                }

                loadProgram.ProgramData = new byte[programInfo.LengthBytes];

                byte bByte  = 0;
                int  iIndex = 0;

                for (int iLoop = 0; iLoop < bNoOfBytes; iLoop++)
                {
                    bByte = rdr.ReadByte();
                    loadProgram.ProgramData[iIndex] = bByte;
                    iIndex++;
                }

                while (bNextSector != 0)
                {
                    strSectorKey = CreateKey(bNextTrack, bNextSector);

                    //byte[] programData = new byte[512];
                    byte[] programData = base.ReadSector(bNextTrack, bNextSector);

                    MemoryStream stm2 = new MemoryStream(programData, 0, programData.Length);
                    BinaryReader rdr2 = new BinaryReader(stm2);

                    bNextTrack  = rdr2.ReadByte();
                    bNextSector = rdr2.ReadByte();
                    bNoOfBytes  = rdr2.ReadByte();

                    for (int iLoop = 0; iLoop < (bNoOfBytes); iLoop++)
                    {
                        try
                        {
                            bByte = rdr2.ReadByte();
                            loadProgram.ProgramData[iIndex] = bByte;
                            iIndex++;
                        }
                        catch (IndexOutOfRangeException)
                        {
                        }
                        catch (EndOfStreamException)
                        {
                        }
                    }
                }
            }

            return(loadProgram);
        }