Exemple #1
0
#pragma warning disable 0169
        private bool SaveQuetzal(int savedPC)
        {
            Quetzal quetzal = new Quetzal();
            // savedPC points to the result storage byte (V3) or branch offset (V4+) of the save instruction
            quetzal.AddBlock("IFhd", MakeIFHD(savedPC));
            quetzal.AddBlock("CMem", CompressRAM());
            quetzal.AddBlock("Stks", SerializeStacks());

            using (Stream stream = io.OpenSaveFile(quetzal.Length))
            {
                if (stream == null)
                {
                    return false;
                }

                try
                {
                    quetzal.WriteToStream(stream);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
Exemple #2
0
        private void SaveQuetzal(byte dest, int nextPC)
        {
            Quetzal quetzal = new Quetzal();
            quetzal.AddBlock("IFhd", MakeIFHD(nextPC - 1));
            quetzal.AddBlock("CMem", CompressRAM());
            quetzal.AddBlock("Stks", SerializeStacks());

            using (Stream stream = io.OpenSaveFile(quetzal.Length))
            {
                if (stream == null)
                {
                    StoreResult(dest, 0);
                    return;
                }

                try
                {
                    quetzal.WriteToStream(stream);
                    StoreResult(dest, 1);
                }
                catch
                {
                    StoreResult(dest, 0);
                }
            }
        }
Exemple #3
0
        private void SaveQuetzal(byte dest, int nextPC)
        {
            Quetzal quetzal = new Quetzal();

            quetzal.AddBlock("IFhd", MakeIFHD(nextPC - 1));
            quetzal.AddBlock("CMem", CompressRAM());
            quetzal.AddBlock("Stks", SerializeStacks());

            using (Stream stream = io.OpenSaveFile(quetzal.Length))
            {
                if (stream == null)
                {
                    StoreResult(dest, 0);
                    return;
                }

                try
                {
                    quetzal.WriteToStream(stream);
                    StoreResult(dest, 1);
                }
                catch
                {
                    StoreResult(dest, 0);
                }
            }
        }
Exemple #4
0
#pragma warning disable 0169
        private bool SaveQuetzal(int savedPC)
        {
            Quetzal quetzal = new Quetzal();

            // savedPC points to the result storage byte (V3) or branch offset (V4+) of the save instruction
            quetzal.AddBlock("IFhd", MakeIFHD(savedPC));
            quetzal.AddBlock("CMem", CompressRAM());
            quetzal.AddBlock("Stks", SerializeStacks());

            using (Stream stream = io.OpenSaveFile(quetzal.Length))
            {
                if (stream == null)
                {
                    return(false);
                }

                try
                {
                    quetzal.WriteToStream(stream);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Exemple #5
0
        private void RestoreQuetzal(byte dest, int failurePC)
        {
            // there are many ways this can go wrong, so let's just assume it will.
            // if the restore succeeds, what we change up here won't matter anyway.
            StoreResult(dest, 0);
            pc = failurePC;

            using (Stream stream = io.OpenRestoreFile())
            {
                if (stream == null)
                    return;

                try
                {
                    Quetzal quetzal = new Quetzal(stream);

                    // verify everything first
                    int savedPC;
                    byte[] ifhd = quetzal.GetBlock("IFhd");
                    if (!VerifyIFHD(ifhd, out savedPC))
                        return;

                    byte[] cmem = quetzal.GetBlock("CMem");
                    byte[] umem;
                    if (cmem != null)
                        umem = UncompressRAM(cmem);
                    else
                        umem = quetzal.GetBlock("UMem");

                    if (umem == null || umem.Length != romStart)
                        return;

                    byte[] stks = quetzal.GetBlock("Stks");
                    Stack<short> savedStack;
                    Stack<CallFrame> savedCallStack;
                    DeserializeStacks(stks, out savedStack, out savedCallStack);
                    if (savedStack == null || savedCallStack == null)
                        return;

                    // ok, restore it
                    SetBytes(0, umem.Length, umem, 0);
                    stack = savedStack;
                    callStack = savedCallStack;
                    SetTopFrame();
                    pc = savedPC;

                    dest = GetByte(pc++);
                    StoreResult(dest, 2);

                    ResetHeaderFields(false);
                }
                catch
                {
                    StoreResult(dest, 0);
                }
            }
        }
Exemple #6
0
        private bool RestoreQuetzal(int failurePC)
        {
            // there are many ways this can go wrong, so let's just assume it will.
            // if the restore succeeds, what we change up here won't matter anyway.
            pc = failurePC;

            using (Stream stream = io.OpenRestoreFile())
            {
                if (stream == null)
                    return false;

                try
                {
                    Quetzal quetzal = new Quetzal(stream);

                    // verify everything first
                    int savedPC;
                    byte[] ifhd = quetzal.GetBlock("IFhd");
                    if (!VerifyIFHD(ifhd, out savedPC))
                        return false;

                    byte[] cmem = quetzal.GetBlock("CMem");
                    byte[] umem;
                    if (cmem != null)
                        umem = UncompressRAM(cmem);
                    else
                        umem = quetzal.GetBlock("UMem");

                    if (umem == null || umem.Length != romStart)
                        return false;

                    byte[] stks = quetzal.GetBlock("Stks");
                    Stack<short> savedStack;
                    Stack<CallFrame> savedCallStack;
                    DeserializeStacks(stks, out savedStack, out savedCallStack);
                    if (savedStack == null || savedCallStack == null)
                        return false;

                    // ok, restore it
                    SetBytes(0, umem.Length, umem, 0);
                    stack = savedStack;
                    callStack = savedCallStack;
                    SetTopFrame();
                    pc = savedPC;

                    if (ZVersion < 4)
                    {
                        // savedPC points to the save instruction's branch offset
                        bool branchIfTrue;
                        int branchOffset;
                        DecodeBranch(ref pc, out branchIfTrue, out branchOffset);
                        if (branchIfTrue)
                            pc += branchOffset - 2;
                    }
                    else
                    {
                        // savedPC points to the save instruction's result storage byte
                        byte dest = GetByte(pc++);
                        StoreResult(dest, 2);
                    }

                    ResetHeaderFields(false);
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
Exemple #7
0
        private void RestoreQuetzal(byte dest, int failurePC)
        {
            // there are many ways this can go wrong, so let's just assume it will.
            // if the restore succeeds, what we change up here won't matter anyway.
            StoreResult(dest, 0);
            pc = failurePC;

            using (Stream stream = io.OpenRestoreFile())
            {
                if (stream == null)
                {
                    return;
                }

                try
                {
                    Quetzal quetzal = new Quetzal(stream);

                    // verify everything first
                    int    savedPC;
                    byte[] ifhd = quetzal.GetBlock("IFhd");
                    if (!VerifyIFHD(ifhd, out savedPC))
                    {
                        return;
                    }

                    byte[] cmem = quetzal.GetBlock("CMem");
                    byte[] umem;
                    if (cmem != null)
                    {
                        umem = UncompressRAM(cmem);
                    }
                    else
                    {
                        umem = quetzal.GetBlock("UMem");
                    }

                    if (umem == null || umem.Length != romStart)
                    {
                        return;
                    }

                    byte[]            stks = quetzal.GetBlock("Stks");
                    Stack <short>     savedStack;
                    Stack <CallFrame> savedCallStack;
                    DeserializeStacks(stks, out savedStack, out savedCallStack);
                    if (savedStack == null || savedCallStack == null)
                    {
                        return;
                    }

                    // ok, restore it
                    SetBytes(0, umem.Length, umem, 0);
                    stack     = savedStack;
                    callStack = savedCallStack;
                    SetTopFrame();
                    pc = savedPC;

                    dest = GetByte(pc++);
                    StoreResult(dest, 2);

                    ResetHeaderFields(false);
                }
                catch
                {
                    StoreResult(dest, 0);
                }
            }
        }
Exemple #8
0
        private bool RestoreQuetzal(int failurePC)
        {
            // there are many ways this can go wrong, so let's just assume it will.
            // if the restore succeeds, what we change up here won't matter anyway.
            pc = failurePC;

            using (Stream stream = io.OpenRestoreFile())
            {
                if (stream == null)
                {
                    return(false);
                }

                try
                {
                    Quetzal quetzal = new Quetzal(stream);

                    // verify everything first
                    int    savedPC;
                    byte[] ifhd = quetzal.GetBlock("IFhd");
                    if (!VerifyIFHD(ifhd, out savedPC))
                    {
                        return(false);
                    }

                    byte[] cmem = quetzal.GetBlock("CMem");
                    byte[] umem;
                    if (cmem != null)
                    {
                        umem = UncompressRAM(cmem);
                    }
                    else
                    {
                        umem = quetzal.GetBlock("UMem");
                    }

                    if (umem == null || umem.Length != romStart)
                    {
                        return(false);
                    }

                    byte[]            stks = quetzal.GetBlock("Stks");
                    Stack <short>     savedStack;
                    Stack <CallFrame> savedCallStack;
                    DeserializeStacks(stks, out savedStack, out savedCallStack);
                    if (savedStack == null || savedCallStack == null)
                    {
                        return(false);
                    }

                    // ok, restore it
                    SetBytes(0, umem.Length, umem, 0);
                    stack     = savedStack;
                    callStack = savedCallStack;
                    SetTopFrame();
                    pc = savedPC;

                    if (ZVersion < 4)
                    {
                        // savedPC points to the save instruction's branch offset
                        bool branchIfTrue;
                        int  branchOffset;
                        DecodeBranch(ref pc, out branchIfTrue, out branchOffset);
                        if (branchIfTrue)
                        {
                            pc += branchOffset - 2;
                        }
                    }
                    else
                    {
                        // savedPC points to the save instruction's result storage byte
                        byte dest = GetByte(pc++);
                        StoreResult(dest, 2);
                    }

                    ResetHeaderFields(false);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }