コード例 #1
0
        static public CpcAmsdos GetAmsdos(byte[] arr)
        {
            CpcAmsdos str  = new CpcAmsdos();
            int       size = Marshal.SizeOf(str);
            IntPtr    ptr  = Marshal.AllocHGlobal(size);

            Marshal.Copy(arr, 0, ptr, size);
            str = (CpcAmsdos)Marshal.PtrToStructure(ptr, typeof(CpcAmsdos));
            Marshal.FreeHGlobal(ptr);
            return(str);
        }
コード例 #2
0
        static public byte[] AmsdosToByte(CpcAmsdos obj)
        {
            int len = Marshal.SizeOf(obj);

            byte[] arr = new byte[len];
            IntPtr ptr = Marshal.AllocHGlobal(len);

            Marshal.StructureToPtr(obj, ptr, true);
            Marshal.Copy(ptr, arr, 0, len);
            Marshal.FreeHGlobal(ptr);
            return(arr);
        }
コード例 #3
0
        static public int CalcCheckSum(CpcAmsdos str)
        {
            int size = Marshal.SizeOf(str);

            byte[] arr = new byte[size];
            IntPtr ptr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(str, ptr, true);
            Marshal.Copy(ptr, arr, 0, size);
            Marshal.FreeHGlobal(ptr);
            return(CalcCheckSum(arr));
        }
コード例 #4
0
        static public CpcAmsdos CreeEntete(string nomFic, short start, short length, short entry)
        {
            CpcAmsdos entete = new CpcAmsdos();
            string    nom    = Path.GetFileName(nomFic);
            string    ext    = Path.GetExtension(nomFic);

            // Supprimer exension du nom
            if (ext != "")
            {
                nom = nom.Substring(0, nom.Length - ext.Length).ToUpper();
                ext = ext.Substring(1).ToUpper();
            }

            // Convertir le nom du fichier au format "AMSDOS" 8.3
            string result = "";

            for (int i = 0; i < 8; i++)
            {
                result += i < nom.Length ? nom[i] : ' ';
            }

            for (int i = 0; i < 3; i++)
            {
                result += i < ext.Length ? ext[i] : ' ';
            }

            // Initialisation de l'en-tête avec les valeurs passées en paramètre
            entete.Adress      = start;
            entete.Length      = entete.RealLength = entete.LogicalLength = length;
            entete.FileType    = 2;
            entete.EntryAdress = entry;
            entete.FileName    = result;
            // Calcul du checksum
            entete.CheckSum = (short)CalcCheckSum(entete);
            return(entete);
        }
コード例 #5
0
        static public bool CheckAmsdos(byte[] entete)
        {
            CpcAmsdos enteteAms = GetAmsdos(entete);

            return(CalcCheckSum(entete) == enteteAms.CheckSum);
        }