Beispiel #1
0
        public void SauveSprite(string fileName, string version)
        {
            byte[]       ret = MakeSprite();
            StreamWriter sw  = SaveAsm.OpenAsm(fileName, version);

            SaveAsm.GenereDatas(sw, ret, ret.Length, BitmapCpc.TailleX >> (BitmapCpc.TailleX <= 320 ? 3 : 4));
            SaveAsm.CloseAsm(sw);
            main.SetInfo("Sauvegarde sprite assembleur ok.");
        }
Beispiel #2
0
        public void SauveSpriteCmp(string fileName, string version)
        {
            byte[]       ret    = MakeSprite();
            byte[]       sprCmp = new byte[ret.Length];
            int          l      = PackDepack.Pack(ret, ret.Length, sprCmp, 0);
            StreamWriter sw     = SaveAsm.OpenAsm(fileName, version);

            SaveAsm.GenereDatas(sw, sprCmp, l, 16);
            SaveAsm.CloseAsm(sw);
            main.SetInfo("Sauvegarde sprite assembleur compacté ok.");
        }
Beispiel #3
0
        private void SauveDeltaPack(int adrDeb, int adrMax, int delai, int modeLigne, bool imageMode, bool optimSpeed)
        {
            int sizeDepack = 0;
            int nbImages   = img.main.GetMaxImages();

            byte[][] bufOut = new byte[nbImages << 1][];
            int[]    lg     = new int[nbImages << 1];
            int[]    bank   = new int[nbImages << 1];
            for (int i = 0; i < nbImages << 1; i++)
            {
                bufOut[i] = new byte[0x18000];
            }

            if (adrMax == 0)
            {
                adrMax = 0xBE00;
            }

            // Calcule les animations
            int ltot = 0, maxDepack = 0;
            int posPack = 0;

            if (chkBoucle.Checked)
            {
                img.main.SelectImage(nbImages - 1, true);
                img.Convert(!img.bitmapCpc.isCalc, true);
                lg[posPack] = PackFrame(bufOut[0], ref sizeDepack, true, false, -1, modeLigne, imageMode, optimSpeed);
                if (lg[posPack] > 0)
                {
                    ltot += lg[posPack++];
                }
            }

            img.main.SetInfo("Début sauvegarde animation assembleur...");
            for (int i = 0; i < (imageMode ? 1 : nbImages); i++)
            {
                if (!imageMode)
                {
                    img.main.SelectImage(i, true);
                    img.Convert(!img.bitmapCpc.isCalc, true);
                }
                Application.DoEvents();
                if (chk2Zone.Checked)
                {
                    lg[posPack] = PackFrame(bufOut[posPack], ref sizeDepack, i == 0 && !chkBoucle.Checked, i == 0 && !chkBoucle.Checked, 0, modeLigne, imageMode, optimSpeed);
                    if (lg[posPack] > 0)
                    {
                        ltot += lg[posPack++];
                    }

                    lg[posPack] = PackFrame(bufOut[posPack], ref sizeDepack, i == 0 && !chkBoucle.Checked, i == 0 && !chkBoucle.Checked, 1, modeLigne, imageMode, optimSpeed);
                    if (lg[posPack] > 0)
                    {
                        ltot += lg[posPack++];
                    }
                }
                else
                {
                    lg[posPack] = PackFrame(bufOut[posPack], ref sizeDepack, i == 0 && !chkBoucle.Checked, i == 0 && !chkBoucle.Checked, -1, modeLigne, imageMode, optimSpeed);
                    if (lg[posPack] > 0)
                    {
                        ltot += lg[posPack++];
                    }
                }
                maxDepack = Math.Max(maxDepack, sizeDepack);
            }

            // Sauvegarde
            StreamWriter sw = SaveAsm.OpenAsm(fileName, version);

            if (param.withCode && !chkDataBrut.Checked)
            {
                SaveAsm.GenereEntete(sw, adrDeb);
                if (BitmapCpc.cpcPlus)
                {
                    SaveAsm.GenereInitPlus(sw);
                }
                else
                {
                    SaveAsm.GenereInitOld(sw);
                }
            }
            bool gest128K = chk128Ko.Checked;

            if ((ltot + adrDeb < adrMax) && (ltot + adrDeb < 0xBE00 - maxDepack))
            {
                gest128K = false;
            }

            if (param.withCode && !chkDataBrut.Checked)
            {
                SaveAsm.GenereAffichage(sw, delai, chkBoucle.Checked, gest128K, imageMode);
                if (BitmapCpc.modeVirtuel >= 7)
                {
                    SaveAsm.GenereDrawAscii(sw, rbFrameFull.Checked, rbFrameO.Checked, rbFrameD.Checked, gest128K, imageMode);
                }
                else
                if (chkDirecMem.Checked)
                {
                    SaveAsm.GenereDrawDirect(sw, gest128K);
                }
                else
                {
                    SaveAsm.GenereDrawDC(sw, delai, chkCol.Checked, gest128K, modeLigne == 8 ? 0x3F : modeLigne == 4 ? 0x1F : modeLigne == 2 ? 0xF : 0x7, optimSpeed);
                }
            }
            if ((param.withPalette || param.withCode) && !chkDataBrut.Checked)
            {
                if (BitmapCpc.cpcPlus)
                {
                    SaveAsm.GenerePalettePlus(sw, img);
                }
                else
                {
                    SaveAsm.GenerePaletteOld(sw, img);
                }
            }
            int endBank0 = 0;
            int lbank = 0, numBank = 0xC0;

            for (int i = 0; i < posPack; i++)
            {
                lbank += lg[i];
                if (!chkDataBrut.Checked && gest128K && lbank > (numBank == 0xC0 ? Math.Min((0xBE00 - maxDepack - adrDeb), adrMax - adrDeb) : 0x4000) && (numBank > 0xC0 || lbank + adrDeb - lg[i] > 0x4000))
                {
                    if (numBank == 0xC0)
                    {
                        endBank0 = lbank + adrDeb - lg[i];
                        sw.WriteLine("EndBank0:");
                        numBank = 0xC4;
                    }
                    else
                    {
                        numBank++;
                        if ((numBank & 15) == 8)
                        {
                            numBank += 4;
                        }

                        if ((numBank & 15) == 15)
                        {
                            numBank += 5;
                        }
                    }
                    lbank = lg[i];
                    sw.WriteLine("	ORG	#4000");
                    sw.WriteLine("	Write Direct -1,-1,#"+ numBank.ToString("X2"));
                }
                bank[i] = numBank;
                if (imageMode && lastAscii != '\0')
                {
                    sw.WriteLine("; Type Frame ='" + lastAscii + "'");
                }

                sw.WriteLine("Delta" + i.ToString() + ":\t\t; Taille #" + lg[i].ToString("X4"));
                SaveAsm.GenereDatas(sw, bufOut[i], lg[i], chkDataBrut.Checked ? 3 : 16);
            }
            if (gest128K)
            {
                SaveAsm.GenerePointeurs(sw, posPack, bank, gest128K && numBank > 0xC0);
            }
            else
            if (!imageMode && !chkDataBrut.Checked)
            {
                sw.WriteLine("	DB	#FF			; Fin de l'animation");
                ltot++;
            }
            SaveAsm.GenereFin(sw, ltot, gest128K && endBank0 < 0x8000);
            SaveAsm.CloseAsm(sw);
            for (int i = 0; i < posPack; i++)
            {
                bufOut[i] = null;
            }

            img.main.SetInfo("Longueur totale données animation : " + ltot + " octets.");
            if (!chkDataBrut.Checked && (numBank > 0xC7 || (!chk128Ko.Checked && ltot + adrDeb >= 0xBE00 - maxDepack)))
            {
                MessageBox.Show("Attention ! la taille totale (animation + buffer de décompactage) dépassera " + (chk128Ko.Checked ? "112K" : "48Ko") + ", risque d'écrasement de la mémoire vidéo et plantage..."
                                , "Alerte"
                                , MessageBoxButtons.OK
                                , MessageBoxIcon.Warning);
                img.main.SetInfo("Dépassement capacité mémoire...");
            }
            else
            {
                img.main.SetInfo("Sauvegarde animation assembleur ok.");
            }

            GC.Collect();
        }
Beispiel #4
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);
        }