Ejemplo n.º 1
0
        public void SauveImp(string fileName)
        {
            int nbImages = main.GetMaxImages();
            int l        = 0;

            for (int i = 0; i < nbImages; i++)
            {
                main.SelectImage(i, true);
                Convert(!bitmapCpc.isCalc, true);
                l += MakeSprite().Length;
            }
            l += 3;             // 3 octets de fin de fichier
            byte[]       endData = { (byte)nbImages, (byte)(BitmapCpc.TailleX >> 3), (byte)(BitmapCpc.TailleY >> 1) };
            CpcAmsdos    entete  = CpcSystem.CreeEntete(fileName, 0x4000, (short)l, -13622);
            BinaryWriter fp      = new BinaryWriter(new FileStream(fileName, FileMode.Create));

            fp.Write(CpcSystem.AmsdosToByte(entete));
            for (int i = 0; i < nbImages; i++)
            {
                main.SelectImage(i, true);
                byte[] sprite = MakeSprite();
                fp.Write(sprite, 0, sprite.Length);
            }
            fp.Write(endData, 0, endData.Length);
            fp.Close();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        private void bpRead_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "Modèle Sprites (.spr)|*.spr";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try {
                    FileStream fileScr  = new FileStream(dlg.FileName, FileMode.Open, FileAccess.Read);
                    byte[]     tabBytes = new byte[fileScr.Length];
                    fileScr.Read(tabBytes, 0, tabBytes.Length);
                    fileScr.Close();
                    if (CpcSystem.CheckAmsdos(tabBytes))
                    {
                        CpcAmsdos enteteAms = CpcSystem.GetAmsdos(tabBytes);
                        // Décodage sprite
                        int pos       = 0;
                        int startBank = enteteAms.RealLength == 0x1000 ? numBank : 0;
                        for (int bank = startBank; bank < 4; bank++)
                        {
                            for (int i = 0; i < 16; i++)
                            {
                                for (int y = 0; y < 16; y++)
                                {
                                    for (int x = 0; x < 16; x++)
                                    {
                                        BitmapCpc.spritesHard[bank, i, x, y] = tabBytes[128 + pos++];
                                        if (pos >= enteteAms.RealLength)
                                        {
                                            x    = 16;
                                            y    = 16;
                                            i    = 16;
                                            bank = 4;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    string filePalette = Path.ChangeExtension(dlg.FileName, "kit");
                    if (File.Exists(filePalette))
                    {
                        main.ReadPaletteKit(filePalette, colors);
                    }
                }
                catch {
                    main.DisplayErreur("Impossible de lire les sprites.");
                }
                DrawMatrice();
            }
        }
Ejemplo n.º 6
0
        public void SavePaletteKit(string fileName, int[] palette)
        {
            CpcAmsdos    entete = CpcSystem.CreeEntete(Path.GetFileName(fileName), -32768, 30, 0);
            BinaryWriter fp     = new BinaryWriter(new FileStream(fileName, FileMode.Create));

            fp.Write(CpcSystem.AmsdosToByte(entete));
            for (int i = 0; i < 15; i++)
            {
                int  kit = BitmapCpc.paletteSprite[i + 1];
                byte c1  = (byte)(((kit & 0x0F) << 4) + ((kit & 0xF0) >> 4));
                byte c2  = (byte)(kit >> 8);
                fp.Write(c1);
                fp.Write(c2);
            }
            fp.Close();
            SetInfo(multilingue.GetString("Main.prg.TxtInfo13"));
        }
Ejemplo n.º 7
0
        static public void SauvePalette(string NomFic, ImageCpc bitmapCpc, Param param)
        {
            int i;

            byte[] pal = new byte[239];

            pal[0] = (byte)param.modeVirtuel;
            int indexPal = 3;

            if (param.cpcPlus)
            {
                for (i = 0; i < 16; i++)
                {
                    pal[indexPal++] = (byte)BitmapCpc.CpcVGA[26 - ((BitmapCpc.Palette[i] >> 4) & 0x0F)];
                    pal[indexPal++] = (byte)BitmapCpc.CpcVGA[26 - (BitmapCpc.Palette[i] & 0x0F)];
                    pal[indexPal++] = (byte)BitmapCpc.CpcVGA[26 - ((BitmapCpc.Palette[i] >> 8) & 0x0F)];
                }
                pal[195] = pal[3];
                pal[196] = pal[4];
                pal[197] = pal[5];
            }
            else
            {
                for (i = 0; i < 16; i++)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        pal[indexPal++] = (byte)BitmapCpc.CpcVGA[BitmapCpc.Palette[i]];
                    }
                }

                for (i = 0; i < 12; i++)
                {
                    pal[indexPal++] = pal[i + 3];
                }
            }
            CpcAmsdos    entete = CpcSystem.CreeEntete(NomFic, (short)-30711, (short)pal.Length, (short)-30711);
            BinaryWriter fp     = new BinaryWriter(new FileStream(NomFic, FileMode.Create));

            fp.Write(CpcSystem.AmsdosToByte(entete));
            fp.Write(pal, 0, pal.Length);
            fp.Close();
        }
Ejemplo n.º 8
0
        private void SauveSprites(bool allBank = false)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter = "Modèle Sprites (.spr)|*.spr";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                try {
                    short        size   = (short)(allBank ? 0x4000 : 0x1000);
                    CpcAmsdos    entete = CpcSystem.CreeEntete(Path.GetFileName(dlg.FileName), 0x4000, size, 0);
                    BinaryWriter fp     = new BinaryWriter(new FileStream(dlg.FileName, FileMode.Create));
                    fp.Write(CpcSystem.AmsdosToByte(entete));
                    byte[] buffer    = new byte[size];
                    int    pos       = 0;
                    int    startBank = allBank ? 0 : numBank;
                    int    endBank   = allBank ? 4 : numBank + 1;
                    for (int bank = startBank; bank < endBank; bank++)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            for (int y = 0; y < 16; y++)
                            {
                                for (int x = 0; x < 16; x++)
                                {
                                    buffer[pos++] = BitmapCpc.spritesHard[bank, i, x, y];
                                }
                            }
                        }
                    }
                    fp.Write(buffer);
                    fp.Close();
                    // Sauvegarde palette au format .KIT
                    main.SavePaletteKit(Path.ChangeExtension(dlg.FileName, "kit"), BitmapCpc.paletteSprite);
                }
                catch {
                    main.DisplayErreur("Impossible de sauver les sprites.");
                }
            }
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
0
        private void ReadScreen(string fileName, bool singlePicture = false)
        {
            FileStream fileScr = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            byte[] tabBytes = new byte[fileScr.Length];
            fileScr.Read(tabBytes, 0, tabBytes.Length);
            fileScr.Close();
            int nbImg = 0;

            try {
                bool isImp = false, isScrImp = false;
                if (CpcSystem.CheckAmsdos(tabBytes))
                {
                    int       nbImages = 1, width = 1, height = 1;
                    CpcAmsdos enteteAms = CpcSystem.GetAmsdos(tabBytes);
                    // Vérifier si type scr imp
                    isScrImp = (enteteAms.FileName.EndsWith("SCR") && enteteAms.FileType == 0 && enteteAms.Adress == 0x170);
                    if (!isScrImp)
                    {
                        // Vérifier si type imp
                        if (enteteAms.FileName.EndsWith("IMP"))
                        {
                            int l = tabBytes.Length;
                            nbImages = tabBytes[l - 3];
                            width    = tabBytes[l - 2];
                            height   = tabBytes[l - 1];
                            int animSize = nbImages * width * height;
                            isImp = l - 131 == animSize;                             // 131 + 128 (Amsdos) + 3 (imp)
                        }
                    }
                    if (isImp)
                    {
                        imgCpc.InitBitmapCpc(nbImages, imgSrc.tpsFrame);
                        imgSrc.InitBitmap(nbImages);
                        anim.SetNbImgs(nbImages, imgSrc.tpsFrame);
                        SetInfo(multilingue.GetString("Main.Prg.TxtInfo2") + nbImages + " images.");
                        BitmapCpc.TailleX = width << 3;
                        BitmapCpc.TailleY = height << 1;
                        int x       = BitmapCpc.NbCol;
                        int y       = BitmapCpc.NbLig;
                        int posData = 128;                         // Entête Amsdos
                        for (int i = 0; i < nbImages; i++)
                        {
                            SelectImage(i, true);
                            byte[] tempData = new byte[width * height];
                            Array.Copy(tabBytes, posData, tempData, 0, tempData.Length);
                            posData += tempData.Length;
                            BitmapCpc bmp = new BitmapCpc(tempData, width << 3, height << 1);
                            imgSrc.ImportBitmap(bmp.CreateImageFromCpc(tabBytes.Length - 0x80, param, true), i);
                        }
                    }
                    else
                    if (isScrImp)
                    {
                        BitmapCpc bmp = new BitmapCpc(tabBytes, 0x110);
                        if (singlePicture)
                        {
                            imgSrc.ImportBitmap(bmp.CreateImageFromCpc(tabBytes.Length - 0x80, param), imgCpc.selImage);
                        }
                        else
                        {
                            BitmapCpc.modeVirtuel = param.modeVirtuel = mode.SelectedIndex = tabBytes[0x94] - 0x0E;
                            BitmapCpc.TailleX     = 768;
                            nbLignes.Value        = param.nbLignes = BitmapCpc.NbLig;
                            BitmapCpc.TailleY     = 544;
                            nbCols.Value          = param.nbCols = BitmapCpc.NbCol;
                            BitmapCpc.cpcPlus     = tabBytes[0xBC] != 0;
                            if (BitmapCpc.cpcPlus)
                            {
                                // Palette en 0x0711;
                                for (int i = 0; i < 16; i++)
                                {
                                    BitmapCpc.Palette[i] = ((tabBytes[0x0711 + (i << 1)] << 4) & 0xF0) + (tabBytes[0x0711 + (i << 1)] >> 4) + (tabBytes[0x0712 + (i << 1)] << 8);
                                }
                            }
                            else
                            {
                                // Palette en 0x7E10
                                for (int i = 0; i < 16; i++)
                                {
                                    BitmapCpc.Palette[i] = BitmapCpc.CpcVGA.IndexOf((char)tabBytes[0x7E10 + i]);
                                }
                            }
                            imgSrc.InitBitmap(bmp.CreateImageFromCpc(tabBytes.Length - 0x80, param));
                        }
                    }
                    else
                    {
                        BitmapCpc bmp = new BitmapCpc(tabBytes, 0x80);
                        if (singlePicture)
                        {
                            imgSrc.ImportBitmap(bmp.CreateImageFromCpc(tabBytes.Length - 0x80, param), imgCpc.selImage);
                        }
                        else
                        {
                            imgSrc.InitBitmap(bmp.CreateImageFromCpc(tabBytes.Length - 0x80, param));
                            nbCols.Value      = param.nbCols = BitmapCpc.NbCol;
                            BitmapCpc.TailleX = param.nbCols << 3;
                            nbLignes.Value    = param.nbLignes = BitmapCpc.NbLig;
                            BitmapCpc.TailleY = param.nbLignes << 1;
                            param.modeVirtuel = mode.SelectedIndex = BitmapCpc.modeVirtuel;
                        }
                        SetInfo(multilingue.GetString("Main.prg.TxtInfo3"));
                    }
                }
                else
                {
                    imageStream          = new MemoryStream(tabBytes);
                    imageStream.Position = 0;
                    if (!singlePicture)
                    {
                        imgSrc.InitBitmap(imageStream);
                        nbImg = imgSrc.NbImg;
                        anim.SetNbImgs(nbImg, imgSrc.tpsFrame);
                        chkAllPics.Visible = nbImg > 1;
                        SetInfo(multilingue.GetString("Main.prg.TxtInfo4") + (nbImg > 0 ? (multilingue.GetString("Main.prg.TxtInfo5") + nbImg + " images.") : "."));
                    }
                    else
                    {
                        imgSrc.ImportBitmap(new Bitmap(imageStream), imgCpc.selImage);
                        SetInfo(multilingue.GetString("Main.prg.TxtInfo4"));
                    }
                }
                radioUserSize.Enabled = radioOrigin.Enabled = true;
                Text = "ConvImgCPC - " + Path.GetFileName(fileName);
                if (radioOrigin.Checked)
                {
                    tbxSizeX.Text = imgSrc.GetImage.Width.ToString();
                    tbxSizeY.Text = imgSrc.GetImage.Height.ToString();
                    tbxPosX.Text  = "0";
                    tbxPosY.Text  = "0";
                }
                if (!singlePicture && !isImp)
                {
                    imgCpc.InitBitmapCpc(nbImg, imgSrc.tpsFrame);
                }

                SelectImage(0);
                imgCpc.Reset(true);
                Convert(false);
            }
            catch {
                DisplayErreur(multilingue.GetString("Main.prg.TxtInfo6"));
            }
        }
Ejemplo n.º 11
0
        static public bool CheckAmsdos(byte[] entete)
        {
            CpcAmsdos enteteAms = GetAmsdos(entete);

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