Exemplo n.º 1
0
        public static string GetInstruction(int offset)
        {
            switch (Data.GetArchitechture(offset))
            {
            case Data.Architechture.CPU65C816: return(CPU65C816.GetInstruction(offset));

            case Data.Architechture.APUSPC700: return("");

            case Data.Architechture.GPUSuperFX: return("");
            }
            return("");
        }
Exemplo n.º 2
0
        public static int GetEffectiveAddress(int offset)
        {
            switch (Data.GetArchitechture(offset))
            {
            case Data.Architechture.CPU65C816: return(CPU65C816.GetEffectiveAddress(offset));

            case Data.Architechture.APUSPC700: return(-1);

            case Data.Architechture.GPUSuperFX: return(-1);
            }
            return(-1);
        }
Exemplo n.º 3
0
        public static int GetIntermediateAddress(int offset, bool resolve = false)
        {
            // FIX ME: log and generation of dp opcodes. search references
            switch (Data.GetArchitechture(offset))
            {
            case Data.Architechture.CPU65C816: return(CPU65C816.GetIntermediateAddress(offset, resolve));

            case Data.Architechture.APUSPC700: return(-1);

            case Data.Architechture.GPUSuperFX: return(-1);
            }
            return(-1);
        }
Exemplo n.º 4
0
        public static int Step(int offset, bool branch, bool force, int prevOffset)
        {
            Project.unsavedChanges = true;
            switch (Data.GetArchitechture(offset))
            {
            case Data.Architechture.CPU65C816: return(CPU65C816.Step(offset, branch, force, prevOffset));

            case Data.Architechture.APUSPC700: return(offset);

            case Data.Architechture.GPUSuperFX: return(offset);
            }
            return(offset);
        }
Exemplo n.º 5
0
        public static void RescanInOutPoints()
        {
            for (int i = 0; i < Data.GetROMSize(); i++)
            {
                Data.ClearInOutPoint(i);
            }

            for (int i = 0; i < Data.GetROMSize(); i++)
            {
                if (Data.GetFlag(i) == Data.FlagType.Opcode)
                {
                    switch (Data.GetArchitechture(i))
                    {
                    case Data.Architechture.CPU65C816: CPU65C816.MarkInOutPoints(i); break;

                    case Data.Architechture.APUSPC700: break;

                    case Data.Architechture.GPUSuperFX: break;
                    }
                }
            }

            Project.unsavedChanges = true;
        }
Exemplo n.º 6
0
        public static int AutoStep(int offset, bool harsh, int amount)
        {
            Project.unsavedChanges = true;
            int newOffset = offset, prevOffset = offset - 1, nextOffset = offset;

            if (harsh)
            {
                while (newOffset < offset + amount)
                {
                    nextOffset = Step(newOffset, false, true, prevOffset);
                    prevOffset = newOffset;
                    newOffset  = nextOffset;
                }
            }
            else
            {
                Stack <int> stack        = new Stack <int>();
                List <int>  seenBranches = new List <int>();
                bool        keepGoing    = true;

                while (keepGoing)
                {
                    switch (Data.GetArchitechture(newOffset))
                    {
                    case Data.Architechture.CPU65C816:
                        if (seenBranches.Contains(newOffset))
                        {
                            keepGoing = false;
                            break;
                        }

                        int opcode = Data.GetROMByte(newOffset);

                        nextOffset = Step(newOffset, false, false, prevOffset);
                        int jumpOffset = Step(newOffset, true, false, prevOffset);

                        if (opcode == 0x40 || opcode == 0xCB || opcode == 0xDB || opcode == 0xF8 ||  // RTI WAI STP SED
                            opcode == 0xFB || opcode == 0x00 || opcode == 0x02 || opcode == 0x42 ||     // XCE BRK COP WDM
                            opcode == 0x6C || opcode == 0x7C || opcode == 0xDC || opcode == 0xFC        // JMP JMP JML JSR
                            )
                        {
                            keepGoing = false;
                        }

                        if (opcode == 0x4C || opcode == 0x5C || opcode == 0x80 || opcode == 0x82 ||  // JMP JML BRA BRL
                            opcode == 0x10 || opcode == 0x30 || opcode == 0x50 || opcode == 0x70 ||     // BPL BMI BVC BVS
                            opcode == 0x90 || opcode == 0xB0 || opcode == 0xD0 || opcode == 0xF0        // BCC BCS BNE BEQ
                            )
                        {
                            seenBranches.Add(newOffset);
                        }

                        if (opcode == 0x08)     // PHP
                        {
                            stack.Push(Data.GetMXFlags(newOffset));
                        }
                        else if (opcode == 0x28)       // PLP
                        {
                            if (stack.Count == 0)
                            {
                                keepGoing = false; break;
                            }
                            else
                            {
                                Data.SetMXFlags(newOffset, stack.Pop());
                            }
                        }

                        if (opcode == 0x60 || opcode == 0x6B)     // RTS RTL
                        {
                            if (stack.Count == 0)
                            {
                                keepGoing = false;
                                break;
                            }
                            else
                            {
                                prevOffset = newOffset;
                                newOffset  = stack.Pop();
                            }
                        }
                        else if (opcode == 0x20 || opcode == 0x22)       // JSR JSL
                        {
                            stack.Push(nextOffset);
                            prevOffset = newOffset;
                            newOffset  = jumpOffset;
                        }
                        else
                        {
                            prevOffset = newOffset;
                            newOffset  = nextOffset;
                        }
                        break;

                    case Data.Architechture.APUSPC700:
                    case Data.Architechture.GPUSuperFX:
                        nextOffset = Step(newOffset, false, true, prevOffset);
                        prevOffset = newOffset;
                        newOffset  = nextOffset;
                        break;
                    }

                    Data.FlagType flag = Data.GetFlag(newOffset);
                    if (!(flag == Data.FlagType.Unreached || flag == Data.FlagType.Opcode || flag == Data.FlagType.Operand))
                    {
                        keepGoing = false;
                    }
                }
            }
            return(newOffset);
        }
Exemplo n.º 7
0
        private static int GetLineByteLength(int offset)
        {
            int max = 1, step = 1;
            int size = Data.GetROMSize();

            switch (Data.GetFlag(offset))
            {
            case Data.FlagType.Opcode:
                switch (Data.GetArchitechture(offset))
                {
                case Data.Architechture.CPU65C816: return(CPU65C816.GetInstructionLength(offset));

                case Data.Architechture.APUSPC700: return(1);

                case Data.Architechture.GPUSuperFX: return(1);
                }
                return(1);

            case Data.FlagType.Unreached:
            case Data.FlagType.Operand:
            case Data.FlagType.Data8Bit:
            case Data.FlagType.Graphics:
            case Data.FlagType.Music:
            case Data.FlagType.Empty:
                max = dataPerLine;
                break;

            case Data.FlagType.Text:
                max = 21;
                break;

            case Data.FlagType.Data16Bit:
                step = 2;
                max  = dataPerLine;
                break;

            case Data.FlagType.Data24Bit:
                step = 3;
                max  = dataPerLine;
                break;

            case Data.FlagType.Data32Bit:
                step = 4;
                max  = dataPerLine;
                break;

            case Data.FlagType.Pointer16Bit:
                step = 2;
                max  = 2;
                break;

            case Data.FlagType.Pointer24Bit:
                step = 3;
                max  = 3;
                break;

            case Data.FlagType.Pointer32Bit:
                step = 4;
                max  = 4;
                break;
            }

            int min = step, myBank = offset / bankSize;

            while (
                min < max &&
                offset + min < size &&
                Data.GetFlag(offset + min) == Data.GetFlag(offset) &&
                Data.GetLabel(Util.ConvertPCtoSNES(offset + min)) == "" &&
                (offset + min) / bankSize == myBank
                )
            {
                min += step;
            }
            return(min);
        }
Exemplo n.º 8
0
        private static byte[] SaveVersion1()
        {
            int size = Data.GetROMSize();

            byte[] romSettings = new byte[31];
            romSettings[0] = (byte)Data.GetROMMapMode();
            romSettings[1] = (byte)Data.GetROMSpeed();
            Util.IntegerIntoByteArray(size, romSettings, 2);
            for (int i = 0; i < 0x15; i++)
            {
                romSettings[6 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFC0 + i));
            }
            for (int i = 0; i < 4; i++)
            {
                romSettings[27 + i] = (byte)Data.GetROMByte(Util.ConvertSNEStoPC(0xFFDC + i));
            }

            // TODO put selected offset in save file

            List <byte> label = new List <byte>(), comment = new List <byte>();
            Dictionary <int, string> all_labels = Data.GetAllLabels(), all_comments = Data.GetAllComments();

            Util.IntegerIntoByteList(all_labels.Count, label);
            foreach (KeyValuePair <int, string> pair in all_labels)
            {
                Util.IntegerIntoByteList(pair.Key, label);
                for (int i = 0; i < pair.Value.Length; i++)
                {
                    label.Add((byte)pair.Value[i]);
                }
                label.Add(0);
            }

            Util.IntegerIntoByteList(all_comments.Count, comment);
            foreach (KeyValuePair <int, string> pair in all_comments)
            {
                Util.IntegerIntoByteList(pair.Key, comment);
                for (int i = 0; i < pair.Value.Length; i++)
                {
                    comment.Add((byte)pair.Value[i]);
                }
                comment.Add(0);
            }

            byte[] romLocation = Util.StringToByteArray(currentROMFile);

            byte[] data = new byte[romSettings.Length + romLocation.Length + 8 * size + label.Count + comment.Count];
            romSettings.CopyTo(data, 0);
            for (int i = 0; i < romLocation.Length; i++)
            {
                data[romSettings.Length + i] = romLocation[i];
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + i] = (byte)Data.GetDataBank(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + size + i] = (byte)Data.GetDirectPage(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 2 * size + i] = (byte)(Data.GetDirectPage(i) >> 8);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 3 * size + i] = (byte)(Data.GetXFlag(i) ? 1 : 0);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 4 * size + i] = (byte)(Data.GetMFlag(i) ? 1 : 0);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 5 * size + i] = (byte)Data.GetFlag(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 6 * size + i] = (byte)Data.GetArchitechture(i);
            }
            for (int i = 0; i < size; i++)
            {
                data[romSettings.Length + romLocation.Length + 7 * size + i] = (byte)Data.GetInOutPoint(i);
            }
            // ???
            label.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size);
            comment.CopyTo(data, romSettings.Length + romLocation.Length + 8 * size + label.Count);
            // ???

            return(data);
        }