예제 #1
0
 public void ReadPaletteKit(string fileName, Label[] colors)
 {
     if (File.Exists(fileName))
     {
         FileStream fileScr  = new FileStream(fileName, FileMode.Open, FileAccess.Read);
         byte[]     tabBytes = new byte[fileScr.Length];
         fileScr.Read(tabBytes, 0, tabBytes.Length);
         fileScr.Close();
         if (CpcSystem.CheckAmsdos(tabBytes))
         {
             BitmapCpc.paletteSprite[0] = 0;
             colors[0].BackColor        = Color.Black;
             colors[0].Refresh();
             for (int i = 0; i < 15; i++)
             {
                 int kit = tabBytes[128 + (i << 1)] + (tabBytes[129 + (i << 1)] << 8);
                 int col = (kit & 0xF00) + ((kit & 0x0F) << 4) + ((kit & 0xF0) >> 4);
                 BitmapCpc.paletteSprite[i + 1] = col;
                 colors[i + 1].BackColor        = Color.FromArgb((byte)((col & 0x0F) * 17), (byte)(((col & 0xF00) >> 8) * 17), (byte)(((col & 0xF0) >> 4) * 17));
                 colors[i + 1].Refresh();
             }
             SetInfo(multilingue.GetString("Main.prg.TxtInfo12"));
         }
     }
 }
예제 #2
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();
        }
예제 #3
0
        static public bool LirePalette(string NomFic, ImageCpc bitmapCpc, Param param)
        {
            byte[] entete = new byte[0x80];
            byte[] pal    = new byte[239];

            BinaryReader fp = new BinaryReader(new FileStream(NomFic, FileMode.Open));

            if (fp != null)
            {
                fp.Read(entete, 0, entete.Length);
                fp.Read(pal, 0, pal.Length);
                fp.Close();
                if (CpcSystem.CheckAmsdos(entete) && pal[0] < 11)
                {
                    if (param.cpcPlus)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            int r = 0, v = 0, b = 0;
                            for (int k = 26; k-- > 0;)
                            {
                                if (pal[3 + i * 12] == (byte)BitmapCpc.CpcVGA[k])
                                {
                                    r = (26 - k) << 4;
                                }

                                if (pal[4 + i * 12] == (byte)BitmapCpc.CpcVGA[k])
                                {
                                    b = 26 - k;
                                }

                                if (pal[5 + i * 12] == (byte)BitmapCpc.CpcVGA[k])
                                {
                                    v = (26 - k) << 8;
                                }
                            }
                            BitmapCpc.Palette[i] = r + v + b;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            for (int j = 0; j < 27; j++)
                            {
                                if (pal[3 + i * 12] == (byte)BitmapCpc.CpcVGA[j])
                                {
                                    BitmapCpc.Palette[i] = j;
                                }
                            }
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
예제 #4
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();
            }
        }
예제 #5
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"));
        }
예제 #6
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();
        }
예제 #7
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.");
                }
            }
        }
예제 #8
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"));
            }
        }
예제 #9
0
        static public int SauveScr(string fileName, BitmapCpc bitmapCpc, ImageCpc img, Param param, bool compact, string version = null, int[,] colMode5 = null)
        {
            byte[] bufPack  = new byte[0x8000];
            bool   overscan = (BitmapCpc.NbLig * BitmapCpc.NbCol > 0x3F00);

            if (param.withPalette && version == null)
            {
                if (param.cpcPlus)
                {
                    ModePal[0] = (byte)(BitmapCpc.modeVirtuel | 0x8C);
                    int k = 1;
                    for (int i = 0; i < 16; i++)
                    {
                        ModePal[k++] = (byte)(((BitmapCpc.Palette[i] >> 4) & 0x0F) | (BitmapCpc.Palette[i] << 4));
                        ModePal[k++] = (byte)(BitmapCpc.Palette[i] >> 8);
                    }
                }
                else
                {
                    ModePal[0] = (byte)BitmapCpc.modeVirtuel;
                    for (int i = 0; i < 16; i++)
                    {
                        ModePal[1 + i] = (byte)BitmapCpc.Palette[i];
                    }
                }
            }

            byte[] imgCpc = bitmapCpc.bmpCpc;
            if (!overscan)
            {
                Buffer.BlockCopy(ModePal, 0, imgCpc, 0x17D0, ModePal.Length);
                if (param.withCode && version == null)
                {
                    if (param.cpcPlus)
                    {
                        Buffer.BlockCopy(CodeP0, 0, imgCpc, 0x07D0, CodeP0.Length);
                        Buffer.BlockCopy(CodeP1, 0, imgCpc, 0x0FD0, CodeP1.Length);
                        Buffer.BlockCopy(CodeP3, 0, imgCpc, 0x1FD0, CodeP3.Length);
                    }
                    else
                    {
                        Buffer.BlockCopy(CodeStd, 0, imgCpc, 0x07D0, CodeStd.Length);
                    }

                    if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                    {
                        Buffer.BlockCopy(codeEgx0, 0, imgCpc, 0x37D0, codeEgx0.Length);
                        Buffer.BlockCopy(codeEgx1, 0, imgCpc, 0x2FD0, codeEgx1.Length);
                        imgCpc[0x07F2] = 0xD0;
                        imgCpc[0x07F3] = 0xF7;                          //	CALL 0xF7D0
                        imgCpc[0x37FA] = 0xEF;                          //	Call 0xEFD0
                    }
                }
            }
            else
            {
                if (BitmapCpc.NbLig * BitmapCpc.NbCol > 0x4000)
                {
                    Buffer.BlockCopy(ModePal, 0, imgCpc, 0x600, ModePal.Length);
                    if (param.withCode && version == null)
                    {
                        if (param.cpcPlus)
                        {
                            Buffer.BlockCopy(CodeOvP, 0, imgCpc, 0x621, CodeOvP.Length);
                        }
                        else
                        {
                            Buffer.BlockCopy(CodeOv, 0, imgCpc, 0x611, CodeOv.Length);
                        }

                        if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                        {
                            Buffer.BlockCopy(codeEgx0, 0, imgCpc, 0x1600, codeEgx0.Length);
                            Buffer.BlockCopy(codeEgx1, 0, imgCpc, 0x1640, codeEgx1.Length);
                            if (param.cpcPlus)
                            {
                                imgCpc[0x669] = 0xCD;
                                imgCpc[0x66A] = 0x00;
                                imgCpc[0x66B] = 0x18;                                           // CALL	#1800
                            }
                            else
                            {
                                imgCpc[0x631] = 0x00;
                                imgCpc[0x632] = 0x18;                                           // CALL	#1800
                            }
                            imgCpc[0x1629] = 0x40;
                            imgCpc[0x162A] = 0x18;                              //	CALL	#1840
                        }
                    }
                }
            }

            short     startAdr = (short)(overscan ? 0x200 : 0xC000);
            short     exec     = (short)(overscan ? param.cpcPlus ? 0x821 : 0x811 : 0xC7D0);
            CpcAmsdos entete;
            int       lg = BitmapCpc.BitmapSize;

            if (compact)
            {
                lg = PackDepack.Pack(bitmapCpc.bmpCpc, lg, bufPack, 0) + 1;                 // Prendre 1 octet de marge ?
                if (param.withCode && version == null)
                {
                    Buffer.BlockCopy(codeDepack, 0, bufPack, lg, codeDepack.Length);
                    bufPack[lg + 4]  = (byte)(startAdr & 0xFF);
                    bufPack[lg + 5]  = (byte)(startAdr >> 8);
                    startAdr         = (short)(0xA657 - (lg + codeDepack.Length));
                    bufPack[lg + 1]  = (byte)(startAdr & 0xFF);
                    bufPack[lg + 2]  = (byte)(startAdr >> 8);
                    bufPack[lg + 32] = (byte)(exec & 0xFF);
                    bufPack[lg + 33] = (byte)(exec >> 8);
                    lg  += codeDepack.Length;
                    exec = (short)(0xA657 - codeDepack.Length);
                }
                else
                {
                    startAdr = (short)(0xA657 - lg);
                    exec     = 0;
                }
            }
            if (version != null)
            {
                // Sauvegarde source assembleur
                StreamWriter sw  = SaveAsm.OpenAsm(fileName, version);
                int          org = 0xA500 - lg - (BitmapCpc.modeVirtuel == 5 ? 600 : 0);
                sw.WriteLine("	ORG	#"+ org.ToString("X4"));
                sw.WriteLine("	Nolist");
                sw.WriteLine("ImageCmp:");
                SaveAsm.GenereDatas(sw, bufPack, lg, 16);
                sw.WriteLine("	List");
                if (param.withCode)
                {
                    sw.WriteLine("	RUN	$");
                    sw.WriteLine("_StartDepack:");
                    if (BitmapCpc.modeVirtuel == 3 || BitmapCpc.modeVirtuel == 4)
                    {
                        SaveAsm.GenereAfficheModeEgx(sw, BitmapCpc.Palette, overscan);
                    }
                    else
                    {
                        SaveAsm.GenereFormatEcran(sw);
                        if (BitmapCpc.modeVirtuel == 5)
                        {
                            SaveAsm.GenereAfficheModeX(sw, colMode5, overscan);
                        }
                        else
                        {
                            SaveAsm.GenereAfficheStd(sw, img, BitmapCpc.modeVirtuel, BitmapCpc.Palette, overscan);
                        }
                    }
                }
                SaveAsm.CloseAsm(sw);
            }
            else
            {
                entete = CpcSystem.CreeEntete(fileName, startAdr, (short)lg, exec);
                BinaryWriter fp = new BinaryWriter(new FileStream(fileName, FileMode.Create));
                fp.Write(CpcSystem.AmsdosToByte(entete));
                fp.Write(compact ? bufPack : bitmapCpc.bmpCpc, 0, lg);
                fp.Close();
            }
            return(lg);
        }