Example #1
0
        public M6502(AddressSpace mem)
        {
            Mem = mem;
            M = mem.M;

            InstallOpcodes();

            Clock = 0;
            RunClocks = 0;
            RunClocksMultiple = 1;

            // initialize processor status, bit 5 is always set
            P = 1 << 5;
        }
        public Machine7800(Cart c, InputAdapter ia, int slines, int startl, int fHZ, int sRate, int[] p)
            : base(ia, slines, startl, fHZ, sRate, p, 320)
        {
            Mem = new AddressSpace(this, 16, 6);  // 7800: 16bit, 64byte pages

            _CPU = new M6502(Mem);
            _CPU.RunClocksMultiple = 4;

            Maria = new Maria(this);
            Mem.Map(0x0000, 0x0040, Maria);
            Mem.Map(0x0100, 0x0040, Maria);
            Mem.Map(0x0200, 0x0040, Maria);
            Mem.Map(0x0300, 0x0040, Maria);

            PIA = new PIA(this);
            Mem.Map(0x0280, 0x0080, PIA);
            Mem.Map(0x0480, 0x0080, PIA);
            Mem.Map(0x0580, 0x0080, PIA);  // unsure about this one

            RAM1 = new RAM6116();
            Mem.Map(0x1800, 0x0800, RAM1);

            RAM2 = new RAM6116();
            Mem.Map(0x2000, 0x0800, RAM2);
            Mem.Map(0x0040, 0x00c0, RAM2); // page 0 shadow
            Mem.Map(0x0140, 0x00c0, RAM2); // page 1 shadow
            Mem.Map(0x2800, 0x0800, RAM2); // shadow1
            Mem.Map(0x3000, 0x0800, RAM2); // shadow2
            Mem.Map(0x3800, 0x0800, RAM2); // shadow3

            // Insert the 7800 Highscore cartridge if requested
            if (EMU7800App.Instance.Settings.Use7800HSC)
            {
                HSC = new HSC7800();
                Mem.Map(0x1000, 0x800, HSC.SRAM);
                Mem.Map(0x3000, 0x1000, HSC);
                Trace.WriteLine("7800 Highscore Cartridge Installed");
            }

            Cart = c;
            Mem.Map(0x4000, 0xc000, Cart);
        }
        public Machine2600(Cart c, InputAdapter ia, int slines, int startl, int fHZ, int sRate, int[] p)
            : base(ia, slines, startl, fHZ, sRate, p, 160)
        {
            Mem = new AddressSpace(this, 13, 6);  // 2600: 13bit, 64byte pages

            _CPU = new M6502(Mem);
            _CPU.RunClocksMultiple = 1;

            TIA = new TIA(this);
            for (ushort i = 0; i < 0x1000; i += 0x100)
            {
                Mem.Map(i, 0x0080, TIA);
            }

            PIA = new PIA(this);
            for (ushort i = 0x0080; i < 0x1000; i += 0x100)
            {
                Mem.Map(i, 0x0080, PIA);
            }

            Mem.Map(0x1000, 0x1000, c);
        }
Example #4
0
 public void Map(AddressSpace mem)
 {
     Mem = mem;
 }
 public void Map(AddressSpace adrspc)
 {
 }
 public void Map(AddressSpace mem)
 {
 }
Example #7
0
 public void Map(AddressSpace mem)
 {
     if (mem == null)
     {
         throw new ArgumentNullException("mem");
     }
     _M = mem.M;
 }
 static int InstructionLength(AddressSpace mem, ushort PC)
 {
     switch (AddressingModeMatrix[mem[PC]])
     {
         case a.ACC:
         case a.IMP:
             return 1;
         case a.REL:
         case a.ZPG:
         case a.ZPX:
         case a.ZPY:
         case a.IDX:
         case a.IDY:
         case a.IMM:
             return 2;
         case a.ABS:
         case a.ABX:
         case a.ABY:
         case a.IND:
         default:
             return 3;
     }
 }
        static string EA(AddressSpace mem, ushort PC, int bytes)
        {
            byte lsb = mem[PC];
            byte msb = 0;

            if (bytes == 2)
            {
                msb = mem[(ushort)(PC + 1)];
            }

            ushort ea = (ushort)(lsb | (msb << 8));

            if (bytes == 1)
            {
                return String.Format("${0:x2}", ea);
            }
            else
            {
                return String.Format("${0:x4}", ea);
            }
        }
        public static string OpCodeDecode(AddressSpace mem, ushort PC)
        {
            int num_operands = InstructionLength(mem, PC) - 1;
            ushort PC1 = (ushort)(PC + 1);
            string addrmodeStr;

            switch (AddressingModeMatrix[mem[PC]])
            {
                case a.REL:
                    addrmodeStr = String.Format("${0:x4}", (ushort)(PC + (sbyte)(mem[PC1]) + 2));
                    break;
                case a.ZPG:
                case a.ABS:
                    addrmodeStr = EA(mem, PC1, num_operands);
                    break;
                case a.ZPX:
                case a.ABX:
                    addrmodeStr = EA(mem, PC1, num_operands) + ",X";
                    break;
                case a.ZPY:
                case a.ABY:
                    addrmodeStr = EA(mem, PC1, num_operands) + ",Y";
                    break;
                case a.IDX:
                    addrmodeStr = "(" + EA(mem, PC1, num_operands) + ",X)";
                    break;
                case a.IDY:
                    addrmodeStr = "(" + EA(mem, PC1, num_operands) + "),Y";
                    break;
                case a.IND:
                    addrmodeStr = "(" + EA(mem, PC1, num_operands) + ")";
                    break;
                case a.IMM:
                    addrmodeStr = "#" + EA(mem, PC1, num_operands);
                    break;
                default:
                    // a.IMP, a.ACC
                    addrmodeStr = "";
                    break;
            }

            return String.Format("{0} {1}", MnemonicMatrix[mem[PC]], addrmodeStr);
        }
        public static string MemDump(AddressSpace mem, ushort atAddr, ushort untilAddr)
        {
            dSB = new StringBuilder();
            int len = untilAddr - atAddr;

            while (len-- >= 0)
            {
                dSB.Append(String.Format("{0:x4}: ", atAddr));
                for (int i = 0; i < 8; i++)
                {
                    dSB.Append(String.Format("{0:x2} ", mem[atAddr++]));
                    if (i == 3)
                    {
                        dSB.Append(" ");
                    }
                }
                dSB.Append("\n");
            }
            if (dSB.Length > 0)
            {
                dSB.Length--;  // Trim trailing newline
            }
            return dSB.ToString();
        }
        public static string Disassemble(AddressSpace mem, ushort atAddr, ushort untilAddr)
        {
            dSB = new StringBuilder();

            dPC = atAddr;
            while (atAddr < untilAddr)
            {
                dSB.Append(String.Format("{0:x4}: ", dPC));

                int len = InstructionLength(mem, dPC);

                for (int i = 0; i < 3; i++)
                {
                    if (i < len)
                    {
                        dSB.Append(String.Format("{0:x2} ", mem[atAddr++]));
                    }
                    else
                    {
                        dSB.Append("   ");
                    }
                }
                dSB.Append(String.Format("{0,-15:s}\n", OpCodeDecode(mem, dPC)));

                dPC += (ushort)len;
            }
            if (dSB.Length > 0)
            {
                dSB.Length--;  // Trim trailing newline
            }
            return dSB.ToString();
        }