예제 #1
0
        /// <summary>
        /// Handles file selection option from open file dialog window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dlgOpenFile_FileOk(object sender, CancelEventArgs e)
        {
            if (null == (m_dskInfo = SimpleDisk.CreateInstance(dlgOpenFile.FileName)))
            {
                lblInfo.Text = "Image is not a valid CoCo disk!";
                return;
            }

            tabMain.Enabled = true;

            lblInfo.Text = String.Format(@"       Tracks: {0}
 Track Length: {1} bytes
     Granules: {2}
Free Granules: {3}
   Free Space: {4} bytes
   Used Space: {5} bytes
        Files: {6}",
                                         m_dskInfo.Tracks,
                                         m_dskInfo.TrackLength,
                                         m_dskInfo.Granules.Length,
                                         m_dskInfo.FreeGranules,
                                         m_dskInfo.FreeGranules * 2304,
                                         (68 - m_dskInfo.FreeGranules) * 2304,
                                         m_dskInfo.Files.Count);

            lstFiles.Nodes.Clear();
            foreach (DirectoryEntry de in m_dskInfo.Directory)
            {
                TreeNode file = new TreeNode(de.Name);
                file.Nodes.Add(String.Format("Type: {0}", de.FileType));

                SimpleFile sf = de.GetFile();
                switch (de.FileType)
                {
                case FileTypes.Assembly:
                    AssemblyFile af = (AssemblyFile)sf;
                    file.Nodes.Add(String.Format("Length: {0}", af.BlockLength));
                    file.Nodes.Add(String.Format("Load Addr: {0}", af.LoadAddress));
                    file.Nodes.Add(String.Format("Exec Addr: {0}", af.ExecAddress));
                    break;

                default:
                    break;
                }

                //file.Nodes.Add (String.Format ("Length: {0}", de.Length));
                //file.Nodes.Add (String.Format ("Granule: {0}", de.Granule));
                lstFiles.Nodes.Add(file);
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the disk image at the specified location and returns either a DMKDisk or RealDisk
        /// object.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        static public SimpleDisk CreateInstance(string path)
        {
            FileInfo   info = null;
            SimpleDisk dsk  = null;

            // quit if the file doesn't exist
            if (!File.Exists(path))
            {
                return(null);
            }

            // get the file info
            info = new FileInfo(path);

            // figure out what type of image this is
            switch (info.Length)
            {
            case 224016:
                dsk = new DMKVirtualDisk();
                break;

            case 161280:
            case 156672:
                dsk = new RawDisk();
                break;

            default:
                break;
            }

            // unknown type, based on size alone
            if (null == dsk)
            {
                return(null);
            }

            // initialize the disk object
            dsk.Initialize(path);
            return(dsk);
        }
예제 #3
0
        /// <summary>
        /// Creates an instance of DirectoryEntry object using binary data from the sector
        /// </summary>
        /// <param name="disk"></param>
        /// <param name="entry"></param>
        /// <returns></returns>
        public static DirectoryEntry CreateInstance(SimpleDisk disk, byte [] entry)
        {
            /*
             * entry contains specific information (bytes listed):
             *      0 - 7	= file name
             *      8 - 10	= file extension
             *      11		= file type
             *      12		= ascii/binary flag (0 = bin, 255 = asc)
             *      13		= first granule number
             *      14 - 15	= number of bytes in last granule
             *      16 - 31 = reserved
             */

            // quit for bad data
            if (null == entry || 32 != entry.Length)
            {
                return(null);
            }

            // check for unused entry name - if bit 7 is set, then
            // entry is not in use.
            if ((0x80 & entry [0]) == 0x80)
            {
                return(null);
            }

            DirectoryEntry di = new DirectoryEntry(disk);

            string name = Encoding.ASCII.GetString(entry, 0, 8);
            string ext  = Encoding.ASCII.GetString(entry, 8, 3);

            // create file handler for specified type
            di.Name             = String.Format("{0}.{1}", name.Trim(), ext.Trim());
            di.FileType         = (FileTypes)entry [11];
            di.StartGranule     = entry [13];
            di.LastSectorLength = ((int)entry [14]) * 256 + (int)entry [15];

            return(di);
        }
예제 #4
0
 /// <summary>
 /// Private constructor
 /// </summary>
 /// <param name="disk"></param>
 private DirectoryEntry(SimpleDisk disk)
 {
     Disk = disk;
 }