예제 #1
0
        static void Main()
        {
            Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            Trace.WriteLine(string.Format("Environment.OSVersion.Platform: {0}", Environment.OSVersion.Platform));
            Trace.WriteLine(string.Format("Environment.OSVersion.VersionString: {0}", Environment.OSVersion.VersionString));
            Trace.WriteLine(string.Format("RuntimeInformation.FrameworkDescription: {0}", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription));


            Form1 form = new Form1();


            osdcore_WinForms              osdcore      = new osdcore_WinForms();
            osd_file_WinForms             osdfile      = new osd_file_WinForms();
            osd_directory_static_WinForms osddirectory = new osd_directory_static_WinForms();
            osd_options_WinForms          options      = new osd_options_WinForms();
            osd_interface_WinForms        osd          = new osd_interface_WinForms(options);

            osd.register_options();
            cli_frontend frontend = new cli_frontend(options, osd);

            // to jump to a specific game on startup
            //string gamename = "___empty";
            //string gamename = "puckman";
            //string gamename = "pacman";
            //string gamename = "mspacman";
            //string gamename = "pacplus";
            //string gamename = "galaga";
            //string gamename = "xevious";
            //string gamename = "digdug";
            //string gamename = "1942";
            //string gamename = "paperboy";
            //options.set_value(emu_options.OPTION_SYSTEMNAME, gamename, g.OPTION_PRIORITY_MAXIMUM);

            osdcore_global.set_osdcore(osdcore);
            osdfile_global.set_osdfile(osdfile);
            osdfile_global.set_osddirectory(osddirectory);
            mame_machine_manager.instance(options, osd);

            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                Thread.CurrentThread.Name         = "machine_manager.execute()";

                int ret = frontend.execute(new std.vector <string>(Environment.GetCommandLineArgs()));

                // tell form that it should close
                form.Invoke((MethodInvoker) delegate { form.Close(); });
            }).Start();


            Application.Run(form);

            mame_machine_manager.close_instance();
            osd.Dispose();
        }
예제 #2
0
        void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.keyboard_state == null)
            {
                return;
            }

            mame.input_item_id input_id;
            if (keymap.TryGetValue(e.KeyCode, out input_id))
            {
                osd.keyboard_state[(int)input_id].i = 0;
            }

            if (e.KeyCode == Keys.ShiftKey)
            {
                if (keymap.TryGetValue(Keys.LShiftKey, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
                if (keymap.TryGetValue(Keys.RShiftKey, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
            }

            if (e.KeyCode == Keys.Menu)
            {
                if (keymap.TryGetValue(Keys.LMenu, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
                if (keymap.TryGetValue(Keys.RMenu, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
            }

            if (e.KeyCode == Keys.ControlKey)
            {
                if (keymap.TryGetValue(Keys.LControlKey, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
                if (keymap.TryGetValue(Keys.RControlKey, out input_id))
                {
                    osd.keyboard_state[(int)input_id].i = 0;
                }
            }
        }
예제 #3
0
        public override int Read(short[] buffer, int offset, int sampleCount)
        {
            int actualCount = 0;

            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                //while (actualCount < sampleCount)
                //{
                //    buffer[actualCount + offset] = 0;  // 20000;
                //    actualCount++;
                //}
                buffer[0] = 0;
                actualCount++;

                return(actualCount);
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (naudioUpdateCount++ % 10 == 0)
            {
                System.Diagnostics.Trace.WriteLine(string.Format("MameWaveProvider16.Read() - {0} - buffer: {1} offset: {2} sampleCount: {3} osd.m_audiobuffer: {4}", naudioUpdateCount, buffer.Length, offset, sampleCount, osd.m_audiobuffer.Count));
            }

            lock (osd.osdlock_audio)
            {
                for (int i = 0; i < sampleCount; i++)
                {
                    if (osd.m_audiobuffer.Count == 0)
                    {
                        break;
                    }

                    Int16 sample = osd.m_audiobuffer.Dequeue();
                    buffer[i + offset] = sample;
                    actualCount++;
                }

                osd.m_audiobuffer.Clear();

                //while (actualCount < sampleCount)
                //{
                //    buffer[actualCount + offset] = 0;  // 20000;
                //    actualCount++;
                //}

                if (actualCount == 0)
                {
                    buffer[0] = 0;
                    actualCount++;
                }
            }

            return(actualCount);
        }
예제 #4
0
        void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.keyboard_state == null)
            {
                return;
            }

            osd.ui_input_push_char_event(e.KeyChar);
        }
예제 #5
0
        void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int mouseX = e.X;
            int mouseY = e.Y;

            int button = -1;

            switch (e.Button)
            {
            case MouseButtons.Left:     button = 0; break;

            case MouseButtons.Right:    button = 1; break;

            case MouseButtons.Middle:   button = 2; break;

            case MouseButtons.XButton1: button = 3; break;

            case MouseButtons.XButton2: button = 4; break;

            case MouseButtons.None:
            default: break;
            }

            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.mouse_button_state == null)
            {
                return;
            }

            Console.WriteLine("Form1_MouseDoubleClick() - '{0}' - '{1}'", e.Button, button);

            if (button != -1)
            {
                osd.mouse_button_state[button].i = 0;

                if (button == 0)
                {
                    osd.ui_input_push_mouse_double_click_event(mouseX, mouseY);
                }
            }
        }
예제 #6
0
        void Form1_MouseLeave(object sender, EventArgs e)
        {
            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.mouse_axis_state == null)
            {
                return;
            }

            Console.WriteLine("Form1_MouseLeave()");

            osd.ui_input_push_mouse_leave_event();
        }
예제 #7
0
        void Form1_MouseWheel(object sender, MouseEventArgs e)
        {
            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.mouse_button_state == null)
            {
                return;
            }


            int   mouseX     = e.X;
            int   mouseY     = e.Y;
            short mouseDelta = (short)e.Delta;
            int   numberOfTextLinesToMove = Math.Abs(e.Delta * SystemInformation.MouseWheelScrollLines / 120);

            osd.ui_input_push_mouse_wheel_event(mouseX, mouseY, mouseDelta, numberOfTextLinesToMove);
        }
예제 #8
0
        void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            int mouseX = e.X;
            int mouseY = e.Y;

            //float dpiX = m_graphics.DpiX;
            //float dpiY = m_graphics.DpiY;
            //float scaleX = dpiX / 96.0f;
            //float scaleY = dpiY / 96.0f;
            float dpiX   = 96;
            float scaleX = 1;
            float scaleY = 1;

            mouseX -= m_bitmapXOffset;
            mouseY -= m_bitmapYOffset;

            mouseX = (int)(mouseX / scaleX);
            mouseY = (int)(mouseY / scaleY);


            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.mouse_axis_state == null)
            {
                return;
            }

            Console.WriteLine("Form1_MouseMove() - '{0}' - '{1}' - '{2}' - '{3}'", mouseX, mouseY, dpiX, scaleX);

            osd.mouse_axis_state[0].i = mouseX;
            osd.mouse_axis_state[1].i = mouseY;

            osd.ui_input_push_mouse_move_event(mouseX, mouseY);
        }
예제 #9
0
        void updateTimer_Tick(object sender, EventArgs e)
        {
            if (m_updateCount++ % 100 == 0)
            {
                Console.WriteLine("updateTimer_Tick() - {0}", m_updateCount);
            }


            if (mame.mame_machine_manager.instance() == null)
            {
                return;  // mame's not ready to update yet
            }
            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            mame.Pointer <byte>             framedata = osd.screenbufferptr;
            ConcurrentDictionary <int, int> frameDataCopyThreadIds = new ConcurrentDictionary <int, int>();

            if (framedata == null)
            {
                return;
            }

#if true
            lock (osd.osdlock)
            {
                //if (Width != m_bitmap.Width || Height != m_bitmap.Height ||
                //    Width != osd.get_width() || Height != osd.get_height())
                //{
                //    m_bitmap = new Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                //    m_bitmapHelper = new BitmapHelper(m_bitmap);
                //
                //    osd.set_bounds(Width, Height);
                //
                //    framedata = osd.screenbufferptr;
                //}

                // right now the source and target bitmaps are different sizes, so detect resizes differently for each

                if (Width - (m_bitmapXOffset * 2) != m_bitmap.Width || Height - (m_bitmapYOffset * 2) != m_bitmap.Height)
                {
                    m_bitmap       = new Bitmap(Width - (m_bitmapXOffset * 2), Height - (m_bitmapYOffset * 2), System.Drawing.Imaging.PixelFormat.Format32bppRgb);
                    m_bitmapHelper = new BitmapHelper(m_bitmap);

                    m_graphics = CreateGraphics();
                }

                if (osd.get_width() != 600 || osd.get_height() != 600)
                {
                    osd.set_bounds(600, 600);

                    framedata = osd.screenbufferptr;
                }

                m_bitmapHelper.Lock();

#if false
                {
                    // random dots to make sure things are working, and not frozen
                    int    stride = osd.get_width();
                    int    x      = 200;
                    int    y      = 100;
                    Random r      = new System.Random();
                    if (x + 10 < osd.get_width() && y + 60 < osd.get_height())
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + (y * stride) + i, (UInt32)(r.Next() % 16000000));
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 10) * stride) + i, mame.rgb_t.white());
                        }

#if false
                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 20) * stride) + i, mame.rgb_t.red);
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 30) * stride) + i, mame.rgb_t.green);
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 40) * stride) + i, mame.rgb_t.blue);
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 50) * stride) + i, mame.rgb_t.pink);
                        }

                        for (int i = 0; i < 10; i++)
                        {
                            framedata.set_uint32(x + ((y + 60) * stride) + i, mame.rgb_t.greenyellow);
                        }
#endif
                    }
                }
#endif

                {
                    // copy whole line at once
                    int sourceWidth       = osd.get_width();
                    int sourceHeight      = osd.get_height();
                    int sourceBytesPerPix = 4;  // TODO query this
                    int sourceStride      = sourceWidth * sourceBytesPerPix;
                    int destWidth         = m_bitmapHelper.Width;
                    int destHeight        = m_bitmapHelper.Height;
                    int destBytesPerPix   = 4; // TODO fix funcs in BitmapHelper and query this
                    int destStride        = destWidth * destBytesPerPix;

                    // if dest is smaller than source, clamp
                    sourceHeight = Math.Min(sourceHeight, destHeight);
                    int copyLength = Math.Min(sourceStride, destStride);

                    System.Threading.Tasks.Parallel.For(0, sourceHeight, y =>
                                                                                                                 //for (int y = 0; y < sourceHeight; y++)
                    {
                        frameDataCopyThreadIds.TryAdd(System.Threading.Thread.CurrentThread.ManagedThreadId, 0); // count how many threads are in use when using Parallel.For() version
                        framedata.CopyTo(y * sourceStride, m_bitmapHelper.GetBitmapData(y * destStride, copyLength), copyLength);
                    });
                }

#if false
                // copy pixel by pixel

                BitmapHelper.SetPixelRawFunc setPixelFunc = m_bitmapHelper.IsAlphaBitmap ? m_bitmapHelper.SetPixelRawAlpha : (BitmapHelper.SetPixelRawFunc)m_bitmapHelper.SetPixelRawNoAlpha;
                int       destPixelSize = m_bitmapHelper.GetRawPixelSize();
                const int scale         = 1;
                for (int y = 0; y < osd.get_height(); y++)
                {
                    int sourceArrayIndex = y * osd.get_height();

                    for (int j = 0; j < scale; j++)
                    {
                        int destArrayIndex = m_bitmapHelper.GetRawYIndex((y * scale) + j);

                        for (int x = 0; x < osd.get_width(); x++)
                        {
                            UInt32 color = framedata.get_uint32(sourceArrayIndex + x);

                            for (int i = 0; i < scale; i++)
                            {
                                setPixelFunc(destArrayIndex, color);
                                destArrayIndex += destPixelSize;
                            }
                        }
                    }
                }
#endif

                m_bitmapHelper.Unlock(true);
            }
#endif


            if (m_graphics != null)
            {
                m_graphics.DrawImageUnscaled(m_bitmap, m_bitmapXOffset, m_bitmapYOffset);
                //m_graphics.DrawImage(m_bitmap, m_bitmapXOffset, m_bitmapYOffset, Width - (m_bitmapXOffset * 3), Height - (m_bitmapYOffset * 3));

                if (mame.mame_machine_manager.instance().machine() == null || mame.mame_machine_manager.instance().machine().phase() != mame.machine_phase.RUNNING)
                {
                    return;
                }

                var         video                    = mame.mame_machine_manager.instance().machine().video();
                osd_ticks_t tps                      = mame.osdcore_global.m_osdcore.osd_ticks_per_second();
                double      final_real_time          = tps == 0 ? 0 : (double)video.m_overall_real_seconds + (double)video.m_overall_real_ticks / (double)tps;
                double      final_emu_time           = video.m_overall_emutime.as_double();
                double      average_speed_percentage = final_real_time == 0 ? 0 : 100 * final_emu_time / final_real_time;
                string      total_time               = (video.m_overall_emutime + new mame.attotime(0, mame.attotime_global.ATTOSECONDS_PER_SECOND / 2)).as_string(2);
                this.Text = string.Format("Emulator running... Avg Speed: {0:f2}% ({1} seconds) Framedata_Copy_Threads: {2} - speed_text: {3}", average_speed_percentage, total_time, frameDataCopyThreadIds.Count, video.speed_text());
            }
        }
예제 #10
0
        void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (mame.mame_machine_manager.instance() == null || mame.mame_machine_manager.instance().osd() == null)
            {
                return;
            }


            //for (int i = 0; i < 256; i++)
            //{
            //    if (Convert.ToBoolean(GetAsyncKeyState(i)))
            //        Console.WriteLine("---------- '{0}' '{1}'", i, (Keys)i);
            //}


            Keys keycode = e.KeyCode;

            if (e.KeyCode == Keys.ShiftKey)
            {
                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.LShiftKey)))
                {
                    keycode = Keys.LShiftKey;
                }

                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.RShiftKey)))
                {
                    keycode = Keys.RShiftKey;
                }
            }

            if (e.KeyCode == Keys.Menu)
            {
                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.LMenu)))
                {
                    keycode = Keys.LMenu;
                }

                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.RMenu)))
                {
                    keycode = Keys.RMenu;
                }
            }

            if (e.KeyCode == Keys.ControlKey)
            {
                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.LControlKey)))
                {
                    keycode = Keys.LControlKey;
                }

                if (Convert.ToBoolean(GetAsyncKeyState((int)Keys.RControlKey)))
                {
                    keycode = Keys.RControlKey;
                }
            }

            Console.WriteLine("Form1_KeyDown() - '{0}' - '{1}' - '{2}' - '{3}'", e.KeyCode, e.KeyData, e.KeyValue, keycode);

            osd_interface_WinForms osd = (osd_interface_WinForms)mame.mame_machine_manager.instance().osd();

            if (osd.keyboard_state == null)
            {
                return;
            }

            mame.input_item_id input_id;
            if (keymap.TryGetValue(keycode, out input_id))
            {
                osd.keyboard_state[(int)input_id].i = 1;
            }


            // from Windows.Forms.Keys
            //  O = 79,
            //  K = 75,
#if false
            if (key >= 65 && key <= 90)
            {
                keyboard_state[ITEM_ID_A + (key - 65)] = 1;
            }
            else if (key >= 48 && key <= 57)
            {
                keyboard_state[ITEM_ID_0 + (key - 48)] = 1;
            }
            else if (key == 13)
            {
                keyboard_state[ITEM_ID_ENTER] = 1;
            }
            else if (key == 27)
            {
                keyboard_state[ITEM_ID_ESC] = 1;
            }
            else if (key == 32)
            {
                keyboard_state[ITEM_ID_SPACE] = 1;
            }
            else if (key == 37)
            {
                keyboard_state[ITEM_ID_LEFT] = 1;
            }
            else if (key == 38)
            {
                keyboard_state[ITEM_ID_UP] = 1;
            }
            else if (key == 39)
            {
                keyboard_state[ITEM_ID_RIGHT] = 1;
            }
            else if (key == 40)
            {
                keyboard_state[ITEM_ID_DOWN] = 1;
            }
#endif
        }