Esempio n. 1
0
        public Cpu(Form form1_reference, ref Memory memory, ref Video video, ref Sound sound, ref Input input)
        {
            _memory = memory;
            _video = video;
            _sound = sound;
            _input = input;
            cycles = 0;
            extra_cycles = 0;
            frame = 0;
            byte_temp1 = byte_temp2 = 0;
            ushort_temp1 = ushort_temp2 = 0;
            shift_register = 0;
            shift_register_offset = 0;

            regs.A = regs.B = regs.C = regs.D = regs.E = regs.H = regs.L = 0;
            regs.F = 6;
            pc = 0;
            sp = 0;
            opcode = 0;
            INTE = 0;
            try
            {
                DipSwitch = byte.Parse(((Form1)form1_reference).main_settings.read_config_setting("Game", "Dip_Switch_Total"), System.Globalization.NumberStyles.HexNumber);
            }
            catch
            {
                DipSwitch = 0;
            }

            parity_loopup = new byte[0x100];
            cycles_lookup = new byte[] {
            4, 10,7, 5, 5, 5, 7, 4, 0, 10,7, 5, 5, 5, 7, 4,
            0, 10,7, 5, 5, 5, 7, 4, 0, 10,7, 5, 5, 5, 7, 4,
            0, 10,16,5, 5, 5, 7, 4, 0, 10,16,5, 5, 5, 7, 4,
            0, 10,13,5, 10,10,10,4, 0, 10,13,5, 5, 5, 7, 4,
            5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5,
            5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5,
            5, 5, 5, 5, 5, 5, 7, 5, 5, 5, 5, 5, 5, 5, 7, 5,
            7, 7, 7, 7, 7, 7, 7, 7, 5, 5, 5, 5, 5, 5, 7, 5,
            4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4,
            4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4,
            4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4,
            4, 4, 4, 4, 4, 4, 7, 4, 4, 4, 4, 4, 4, 4, 7, 4,
            5, 10,10,10,11,11,7, 11,5, 10,10,0, 11,17,7, 11,
            5, 10,10,10,11,11,7, 11,5, 0, 10,10,11,0, 7, 11,
            5, 10,10,18,11,11,7, 11,5, 5, 10,4, 11,0, 7, 11,
            5, 10,10,4, 11,11,7, 11,5, 5, 10,4, 11,0, 7, 11
            };

            for (int i = 0; i < parity_loopup.Length; i++)
            {
                parity_loopup[i] = (byte)(4 & (4 ^ (i << 2) ^ (i << 1) ^ i ^ (i >> 1) ^ (i >> 2) ^ (i >> 3) ^ (i >> 4) ^ (i >> 5)));
            }
        }
Esempio n. 2
0
        public void subitem_Start_CPU()
        {
            if (Critical_failure == false)
            {
                try
                {
                    if (video != null && time != null)
                    {
                        if (video.Fatal_error)
                        {
                            MessageBox.Show("The Space Invaders encountered an error loading, \nthis option is not available right now.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }

                        if (time.Enabled || Paused_state == true)
                        {
                            MessageBox.Show("CPU is either currently running or is currently paused, \nthis operation can not continue.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                    }

                    Window_state = FormWindowState.Minimized;
                    Taskbar_visibility = false;
                    Screen_visibility = false;

                    if (video == null)
                    {
                        video = new Video(this);
                        memory = new Memory(this, video);
                        input = new Input(this, video.Directx_Window.Handle);
                        sound = new Sound(this, video);
                        cpu = new Cpu(this, ref memory, ref video, ref sound, ref input);
                    }
                    else
                    {
                        video.reinit_directx();
                        sound.reinit_directsound();
                        input.Reinitialize_Keyboard(video.Directx_Window.Handle);
                        if (cpu == null)
                        {
                            cpu = new Cpu(this, ref memory, ref video, ref sound, ref input);
                        }
                    }

                    if (time == null)
                    {
                        time = new Timer();
                        time.Interval = 15;
                        time.Tick += new EventHandler(time_Tick);
                    }

                    time.Start();
                    video.Directx_Window.Activate();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("A critical error has been detected in the emulator, This menu has been disabled. Please contact author for assistance.", "Error!", MessageBoxButtons.OK);
            }
        }