Exemplo n.º 1
0
        public virtual OricProgram LoadFile(String diskName, OricFileInfo oricFileInfo)
        {
            OricProgram oricProgram = new OricProgram();

            oricProgram.New();

            return(oricProgram);
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        public OricProgram LoadFile()
        {
            OricProgram oricProgram = new OricProgram();

            oricProgram.New();

            if (MediaType == ConstantsAndEnums.MediaType.TapeFile)
            {
                OricTape oricTape = new OricTape();
                oricProgram = oricTape.Load(Path.Combine(Folder, ParentName), ProgramName, ProgramIndex);
            }
            else
            {
                OricDisk oricDisk = new OricDisk();
                oricDisk.LoadDisk(ParentName);

                switch (oricDisk.DOSFormat())
                {
                case OricDisk.DOSFormats.OricDOS:
                {
                    OricDos oricDisc = new OricDos();
                    oricProgram = oricDisc.LoadFile(ParentName, this);
                }
                break;

                case OricDisk.DOSFormats.SedOric:
                {
                    SedOric oricDisc = new SedOric();
                    oricProgram = oricDisc.LoadFile(ParentName, this);
                }
                break;

                case OricDisk.DOSFormats.StratSed:
                {
                    StratSed oricDisc = new StratSed();
                    oricProgram = oricDisc.LoadFile(ParentName, this);
                }
                break;

                case OricDisk.DOSFormats.TDOS:
                {
                    FTDos oricDisc = new FTDos();
                    oricProgram = oricDisc.LoadFile(ParentName, this);
                }
                break;

                default:
                    break;
                }
            }

            return(oricProgram);
        }
Exemplo n.º 5
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();
        }
        private void TextEditorForm_Load(object sender, EventArgs e)
        {
            String strTitleText = Text;

            Text = String.Format("Text Screen Editor - {0}", fileInfo.ProgramName);

            // Initialise program settings
            loadedProgram.New();

            if (mediaType == OricExplorer.MediaType.DiskFile)
            {
                loadedProgram = fileInfo.LoadFile();
            }
            else if (mediaType == OricExplorer.MediaType.TapeFile)
            {
                loadedProgram = oricTape.Load(Path.Combine(tapeInfo.Folder, tapeInfo.Name), fileInfo.ProgramName, fileInfo.ProgramIndex);
            }

            bScrnData = new Byte[loadedProgram.ProgramLength];

            for (int iIndex = 0; iIndex < loadedProgram.ProgramLength; iIndex++)
            {
                bScrnData[iIndex] = loadedProgram.m_programData[iIndex];
            }

            m_ui16StartAddress = loadedProgram.StartAddress;
            m_ui16DisplayBytes = loadedProgram.ProgramLength;

            DrawTextPreview(screenImage);
            pictureBoxEditor.Image = screenImage;

            firstRow = (fileInfo.StartAddress - 0xBBA8) / 40;
            lastRow  = (fileInfo.EndAddress - 0xBBA8) / 40;

            if (FlashTimer == null)
            {
                FlashTimer          = new System.Windows.Forms.Timer();
                FlashTimer.Interval = 700;
                FlashTimer.Start();
                FlashTimer.Tick += new EventHandler(Timer_Tick);
            }

            UpdateStandardImage();

            infoBoxStartAddress.Text = String.Format("${0:X4}", loadedProgram.StartAddress);
            infoBoxEndAddress.Text   = String.Format("${0:X4}", loadedProgram.EndAddress);
            infoBoxLength.Text       = String.Format("{0:N0} bytes ({1:N1} KB)", loadedProgram.ProgramLength, loadedProgram.ProgramLength / 1024);
            infoBoxDimensions.Text   = String.Format("40 columns by {0} rows", lastRow - firstRow);
        }
Exemplo n.º 7
0
        public Boolean SaveFile(String diskName, String fileName, OricProgram program)
        {
            Boolean fileSaved = false;

            // Disk should be loaded
            if (diskLoaded)
            {
                if (dosFormat == DOSFormats.OricDOS)
                {
                    OricDos oricdos = new OricDos();
                    oricdos.SaveFile(diskName, fileName, program, this);
                }
            }

            return(fileSaved);
        }
        //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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public bool SaveFile(OricProgram oricFile)
        {
            // Open the Tape and set pointer to the end of file
            FileStream tapeFile = new FileStream(TapeName, FileMode.Append);

            using (BinaryWriter binWriter = new BinaryWriter(tapeFile))
            {
                // Write the Tape leader
                binWriter.Write((byte)0x16);
                binWriter.Write((byte)0x16);
                binWriter.Write((byte)0x16);
                binWriter.Write((byte)0x24);
                binWriter.Write((byte)0x00);
                binWriter.Write((byte)0x00);

                // Write the Program format
                if (oricFile.Format == OricProgram.ProgramFormat.BasicProgram)
                {
                    binWriter.Write((byte)0x00);
                }
                else
                {
                    binWriter.Write((byte)0x01);
                }

                // Write the Auto run flag
                if (oricFile.AutoRun == OricProgram.AutoRunFlag.Enabled)
                {
                    binWriter.Write((byte)0x01);
                }
                else
                {
                    binWriter.Write((byte)0x00);
                }

                // Get the High and Low bytes of the End address and write to file
                byte hi = Convert.ToByte((oricFile.EndAddress >> 8) & 0xFF);
                byte lo = Convert.ToByte(oricFile.EndAddress & 0xFF);

                binWriter.Write((byte)hi);
                binWriter.Write((byte)lo);

                // Get the High and Low bytes of the Start address and write to file
                hi = Convert.ToByte((oricFile.StartAddress >> 8) & 0xFF);
                lo = Convert.ToByte(oricFile.StartAddress & 0xFF);

                binWriter.Write((byte)hi);
                binWriter.Write((byte)lo);

                // Write unused byte
                binWriter.Write((byte)0x00);

                int iIndex;

                // Write the Program name
                for (iIndex = 0; iIndex < oricFile.ProgramName.Length; iIndex++)
                {
                    binWriter.Write(Convert.ToByte(oricFile.ProgramName[iIndex]));
                }

                // NULL terminate the Program name
                binWriter.Write((byte)0x00);

                // Write file data
                for (iIndex = 0; iIndex < oricFile.ProgramLength; iIndex++)
                {
                    binWriter.Write((byte)oricFile.ProgramData[iIndex]);
                }
            }

            // Close the Tape file
            tapeFile.Close();

            return(true);
        }
Exemplo n.º 12
0
        public OricProgram Load(string strTapeName, string strProgName, ushort siProgIndex)
        {
            ushort i16ProgramCount = 0;
            ushort i16NoNameCount  = 0;

            OricProgram loadProgram = new OricProgram();

            TapeName = strTapeName;

            ReadTapeIntoBuffer();

            m_ui32BufferIdx = 0;

            while (SyncTape() && siProgIndex >= i16ProgramCount)
            {
                // Store the program header
                ProgramHeader programHeader = ReadProgramHeader();

                // Set the parent name
                loadProgram.ParentName = strTapeName;

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

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

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

                if (i16ProgramCount == siProgIndex)
                {
                    ushort ui16Count      = 0;
                    ushort ui16ProgLength = loadProgram.ProgramLength;

                    loadProgram.ProgramData = new byte[ui16ProgLength];

                    do
                    {
                        loadProgram.ProgramData[ui16Count] = m_bTapeBuffer[m_ui32BufferIdx];

                        ui16Count++;
                        m_ui32BufferIdx++;
                    } while((ui16Count < ui16ProgLength) && (m_ui32BufferIdx < m_bTapeBuffer.Length));
                }
                else
                {
                    // Move buffer pointer beyond program data
                    m_ui32BufferIdx += loadProgram.ProgramLength;

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

                i16ProgramCount++;
            }

            return(loadProgram);
        }
Exemplo n.º 13
0
        public bool SaveFile(string diskName, string fileName, OricProgram program, OricDisk disk)
        {
            bool fileSaved = false;

            LoadDisk(diskName);

            // Check if disk has been loaded
            if (DiskLoaded())
            {
                diskInfo = new OricDiskInfo(diskName);

                //ArrayList dir<String, OricFileInfo>
                // Check if file already exists
                OricFileInfo[] diskDirectory = ReadOricDosDirectory();

                int  dirIndex    = 0;
                bool fileMatched = false;

                while (dirIndex < diskDirectory.Length && !fileMatched)
                {
                    if (diskDirectory[dirIndex].ProgramName.Equals(fileName))
                    {
                        fileMatched = true;
                    }

                    dirIndex++;
                }

                if (!fileMatched)
                {
                    nextAvailableTrack  = diskInfo.nextAvailableTrack;
                    nextAvailableSector = diskInfo.nextAvailableSector;

                    int noOfSectors;

                    if (program.ProgramLength < 245)
                    {
                        noOfSectors = 1;
                    }
                    else
                    {
                        int remaining = program.ProgramLength - 245;
                        noOfSectors = remaining / 253;
                    }

                    sectorsFree = (ushort)(diskInfo.SectorsFree - noOfSectors);
                    sectorsUsed = (ushort)(diskInfo.SectorsUsed + noOfSectors);

                    // Write program data
                    WriteProgramData(program);

                    // Update disk directory
                    AddDirectoryEntry(fileName, (ushort)noOfSectors, (byte)nextAvailableTrack, (byte)nextAvailableSector, program.Protection);

                    // Update System sector (free sectors etc)
                    UpdateSystemSector();

                    if (WriteDisk())
                    {
                        MessageBox.Show("Program saved.");
                    }
                    else
                    {
                        MessageBox.Show("Failed to save program");
                    }
                }
            }

            return(fileSaved);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        private void WriteProgramData(OricProgram program)
        {
            // How many sectors are needed
            int programLength = program.ProgramData.Length;
            int noOfSectors;

            if (programLength < 245)
            {
                noOfSectors = 1;
            }
            else
            {
                int remaining = programLength - 245;
                noOfSectors = remaining / 253;
            }

            // Update first sector
            byte[] sectorData = new byte[256];

            // Initialise the sector
            for (int index = 0; index < sectorData.Length; index++)
            {
                sectorData[index] = 0x40;
            }

            sectorData[0x00] = 0x00; // Track pointer to next block
            sectorData[0x01] = 0x00; // Sector pointer to next block

            sectorData[0x02] = 0xFF; // 0xFF - Suitable for !LOAD
            sectorData[0x03] = 0x00;

            // Setup Start address
            sectorData[0x04] = Convert.ToByte((program.StartAddress >> 8) & 0xFF);
            sectorData[0x05] = Convert.ToByte(program.StartAddress & 0xFF);

            // Setup End Address
            sectorData[0x06] = Convert.ToByte((program.EndAddress >> 8) & 0xFF);
            sectorData[0x07] = Convert.ToByte(program.EndAddress & 0xFF);

            if (program.Format == OricProgram.ProgramFormat.BasicProgram)
            {
                if (program.AutoRun == OricProgram.AutoRunFlag.Enabled)
                {
                    sectorData[0x08] = 0x02; // T address or Program type
                    sectorData[0x09] = 0x00; // T address or Program type
                }
                else
                {
                    sectorData[0x08] = 0x01; // T address or Program type
                    sectorData[0x09] = 0x00; // T address or Program type
                }
            }
            else
            {
                if (program.ExeAddress > 0x0000)
                {
                    sectorData[0x08] = Convert.ToByte(program.ExeAddress & 0xFF);
                    sectorData[0x09] = Convert.ToByte((program.ExeAddress >> 8) & 0xFF);
                }
                else
                {
                    sectorData[0x08] = 0x00; // T address or Program type
                    sectorData[0x09] = 0x00; // T address or Program type
                }
            }

            if (noOfSectors > 1)
            {
                sectorData[0x0A] = 0xF5; // 0xF5 = Full otherwise no. of bytes in this block
            }
            else
            {
                sectorData[0x0A] = Convert.ToByte(programLength);
            }

            int sectorPos = 0x0B;
            int dataPos   = 0x00;

            int iFirstTrack  = nextAvailableTrack;
            int iFirstSector = nextAvailableSector;

            // Write program data to first program sector
            while (dataPos < programLength && sectorPos < 0xFF)
            {
                sectorData[sectorPos] = program.ProgramData[dataPos];

                sectorPos++;
                dataPos++;
            }

            // Write program sector to disk
            WriteSector((ushort)iFirstTrack, (ushort)iFirstSector, sectorData);

            // Adjust count of no. of Sectors left to write
            noOfSectors--;

            while (noOfSectors > 0)
            {
                // Find next available Sector
                FindNextAvailableSector(iFirstTrack, iFirstSector, ref nextAvailableTrack, ref nextAvailableSector);

                // Initialise the sector
                for (int index = 0; index < sectorData.Length; index++)
                {
                    sectorData[index] = 0x40;
                }

                sectorData[0x00] = (byte)nextAvailableTrack;
                sectorData[0x01] = (byte)nextAvailableSector;

                if (programLength - dataPos > 0xFD)
                {
                    sectorData[0x02] = 0xFD; // 0xFD = Full otherwise no. of bytes in this block
                }
                else
                {
                    sectorData[0x02] = (byte)(programLength - dataPos);
                }

                sectorPos = 0x03;

                // Write program data to the next program sector
                while (dataPos < programLength && sectorPos < 0xFF)
                {
                    sectorData[sectorPos] = program.ProgramData[dataPos];

                    sectorPos++;
                    dataPos++;
                }

                // Write program sector to disk
                WriteSector((ushort)nextAvailableTrack, (ushort)nextAvailableSector, sectorData);
            }
        }
Exemplo n.º 16
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);
        }