public Machine(InputAdapter ia, int scanLines, int firstScanline, int fHZ, int soundSampleRate, int[] p, int vPitch)
 {
     _InputAdapter = ia;
     _Scanlines = scanLines;
     _FirstScanline = firstScanline;
     _FrameHZ = fHZ;
     _SoundSampleRate = soundSampleRate;
     _Palette = p;
     _VisiblePitch = vPitch;
 }
        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);
        }
 public Machine2600PAL(Cart cart, InputAdapter ia)
     : base(cart, ia, 312, 32, 50, TIASound.PAL_SAMPLES_PER_SEC, TIATables.PALPalette)
 {
     Trace.Write(this);
     Trace.WriteLine(" ready");
 }
 public Machine2600NTSC(Cart cart, InputAdapter ia)
     : base(cart, ia, 262, 16, 60, TIASound.NTSC_SAMPLES_PER_SEC, TIATables.NTSCPalette)
 {
     Trace.Write(this);
     Trace.WriteLine(" ready");
 }
        public static Machine New(GameSettings gs, Cart c, InputAdapter ia)
        {
            if (gs == null)
            {
                throw new ArgumentNullException("gs");
            }
            if (c == null)
            {
                throw new ArgumentNullException("c");
            }
            if (ia == null)
            {
                throw new ArgumentNullException("ia");
            }

            Machine m;

            switch (gs.MachineType)
            {
                case MachineType.A2600NTSC:
                    m = new Machine2600NTSC(c, ia);
                    break;
                case MachineType.A2600PAL:
                    m = new Machine2600PAL(c, ia);
                    break;
                case MachineType.A7800NTSC:
                    m = new Machine7800NTSC(c, ia);
                    break;
                case MachineType.A7800PAL:
                    m = new Machine7800PAL(c, ia);
                    break;
                default:
                    throw new Exception("Unexpected machine type: " + gs.MachineType.ToString());
            }

            m.InputAdapter.Controllers[0] = gs.LController;
            m.InputAdapter.Controllers[1] = gs.RController;

            return m;
        }
 void Start(InputAdapter ia)
 {
     Hide();
     try
     {
         EMU7800App.Instance.RunMachine(CurrGameSettings, ia);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Machine/Host Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         Trace.WriteLine(ex.Message);
         Trace.WriteLine(ex.StackTrace);
     }
     Show();
     StartButtonEnabled = true;
     ResumeButtonEnabled = true;
 }
 public void RunMachine(GameSettings gs, InputAdapter ia)
 {
     if (ia == null)
     {
         ia = new InputAdapter();
     }
     M = Machine.New(gs, Cart.New(gs), ia);
     M.Reset();
     RunMachine();
     M.Done();
 }
 public Machine7800PAL(Cart cart, InputAdapter ia)
     : base(cart, ia, 312, 32, 50, TIASound.PAL_SAMPLES_PER_SEC, MariaTables.PALPalette)
 {
     if (!EMU7800App.Instance.Settings.Skip7800BIOS)
     {
         BIOS = new Bios7800(MachineType.A7800PAL);
     }
     Trace.Write(this);
     Trace.WriteLine(" ready");
 }
 public Machine7800NTSC(Cart cart, InputAdapter ia)
     : base(cart, ia, 262, 16, 60, TIASound.NTSC_SAMPLES_PER_SEC, MariaTables.NTSCPalette)
 {
     if (!EMU7800App.Instance.Settings.Skip7800BIOS)
     {
         BIOS = new Bios7800(MachineType.A7800NTSC);
     }
     Trace.Write(this);
     Trace.WriteLine(" ready");
 }