Beispiel #1
0
        /// <summary>
        /// Generates a CpuDef that best matches the parameters.
        /// </summary>
        /// <param name="type">Specific CPU we want.</param>
        /// <param name="includeUndocumented">Set to true if "undocumented" opcodes should
        ///   be included in the definition.</param>
        /// <returns>Best CpuDef.</returns>
        public static CpuDef GetBestMatch(CpuType type, bool includeUndocumented)
        {
            // Many 65xx variants boil down to a 6502, 65C02, or 65816, at least as far as
            // a disassembler needs to know.  These do not, and would need full definitions:
            //
            //  Hudson Soft HuC6280 (PC Engine / TurboGrafx)
            //  Commodore CSG 4510 / CSG 65CE02 (Amiga A2232 serial port; 4510 has one
            //   additional instruction, so use that as archetype)
            //  Rockwell R65C02 (used in ???)
            //  Jeri's 65DTV02 (used in C64DTV single-chip computer); same as 6502 with
            //   some differences in illegal opcodes
            //  Eloraam 65EL02 (defined in a Minecraft-based emulator)

            CpuDef cpuDef;

            switch (type)
            {
            case CpuType.Cpu65802:
            case CpuType.Cpu65816:
            case CpuType.Cpu5A22:
                cpuDef = Cpu65816;
                break;

            case CpuType.Cpu65C02:
            case CpuType.Cpu65SC02:
                cpuDef = Cpu65C02;
                break;

            default:
                cpuDef = Cpu6502;
                break;
            }

            cpuDef.GenerateCycleCounts();

            // If we don't want undocumented opcodes, strip them out of the definition.
            // Entries are replaced with OpInvalid.
            if (!includeUndocumented)
            {
                CpuDef stripped = new CpuDef(cpuDef);
                for (int i = 0; i < 256; i++)
                {
                    if (cpuDef.mOpDefs[i].IsUndocumented)
                    {
                        stripped.mOpDefs[i] = OpDef.OpInvalid;
                    }
                    else
                    {
                        stripped.mOpDefs[i] = cpuDef.mOpDefs[i];
                    }
                }
                cpuDef = stripped;
            }

            cpuDef.HasUndocumented = includeUndocumented;

            return(cpuDef);
        }
Beispiel #2
0
        /// <summary>
        /// Copy constructor.  Does not copy the contents of mOpDefs.  Only used internally.
        /// </summary>
        /// <param name="src">Object to copy from.</param>
        private CpuDef(CpuDef src)
        {
            Name            = src.Name;
            MaxAddressValue = src.MaxAddressValue;
            HasEmuFlag      = src.HasEmuFlag;
            Type            = src.Type;
            mCycleCounts    = src.mCycleCounts;
            mCycleMods      = src.mCycleMods;

            mOpDefs = new OpDef[256];
        }
Beispiel #3
0
        /// <summary>
        /// Generates a CpuDef that best matches the parameters.
        /// </summary>
        /// <param name="type">Specific CPU we want.</param>
        /// <param name="includeUndocumented">Set to true if "undocumented" opcodes should
        ///   be included in the definition.</param>
        /// <returns>Best CpuDef.</returns>
        public static CpuDef GetBestMatch(CpuType type, bool includeUndocumented)
        {
            // Pretty much everything boils down to a 6502, 65C02, or 65816.
            // The Rockwell R65C02, described in an appendix in Eyes & Lichty, doesn't,
            // and would need its own CpuDef.
            CpuDef cpuDef;

            switch (type)
            {
            case CpuType.Cpu65802:
            case CpuType.Cpu65816:
            case CpuType.Cpu5A22:
                cpuDef = Cpu65816;
                break;

            case CpuType.Cpu65C02:
                cpuDef = Cpu65C02;
                break;

            default:
                cpuDef = Cpu6502;
                break;
            }

            cpuDef.GenerateCycleCounts();

            // If we don't want undocumented opcodes, strip them out of the definition.
            // Entries are replaced with OpInvalid.
            if (!includeUndocumented)
            {
                CpuDef stripped = new CpuDef(cpuDef);
                for (int i = 0; i < 256; i++)
                {
                    if (cpuDef.mOpDefs[i].IsUndocumented)
                    {
                        stripped.mOpDefs[i] = OpDef.OpInvalid;
                    }
                    else
                    {
                        stripped.mOpDefs[i] = cpuDef.mOpDefs[i];
                    }
                }
                cpuDef = stripped;
            }

            cpuDef.HasUndocumented = includeUndocumented;

            return(cpuDef);
        }
Beispiel #4
0
 private static void InternalValidate(CpuDef cdef)
 {
     for (int i = 0; i < 256; i++)
     {
         OpDef op = cdef.mOpDefs[i];
         if (op.Opcode != i && op.AddrMode != OpDef.AddressMode.Unknown)
         {
             throw new Exception("CpuDef for " + cdef.Type + ": entry 0x" +
                                 i.ToString("x") + " has value " + op.Opcode.ToString("x"));
         }
         if (op.AddrMode != OpDef.AddressMode.Unknown && op.Cycles == 0)
         {
             throw new Exception("Instruction 0x" + i.ToString("x2") + ": " +
                                 op + " missing cycles");
         }
     }
 }