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; } } }
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 (this) { 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); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); 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 errorstring; //options.set_value(emu_options.OPTION_SYSTEMNAME, gamename, OPTION_PRIORITY.OPTION_PRIORITY_MAXIMUM, out errorstring); osdcore_global.set_osdcore(osdcore); osdcore_global.set_osdfile(osdfile); osdcore_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(); }
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); } } }
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(); }
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; mouseX -= m_bitmapXOffset; mouseY -= m_bitmapYOffset; mouseX = (int)(mouseX / scaleX); mouseY = (int)(mouseY / scaleY); // HACK for high dpi? until we switch to 4.7? mouseX = (int)(mouseX * 0.83333333f); mouseY = (int)(mouseY * 0.83333333f); 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); }
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.RawBufferPointer framedata = osd.screenbufferptr; if (framedata == null) { return; } #if true lock (osd.osdlock) { m_bitmapHelper.Lock(); //int stride = 640; int stride = 400; Random r = new System.Random(); for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 100 * stride, (UInt32)(r.Next() % 16000000)); } for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 110 * stride, mame.rgb_t.white()); } #if false for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 120 * stride, mame.rgb_t.red); } for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 130 * stride, mame.rgb_t.green); } for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 140 * stride, mame.rgb_t.blue); } for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 150 * stride, mame.rgb_t.pink); } for (int i = 0; i < 10; i++) { framedata.set_uint32(i + 200 + 160 * stride, mame.rgb_t.greenyellow); } #endif BitmapHelper.SetPixelRawFunc setPixelFunc = m_bitmapHelper.IsAlphaBitmap ? m_bitmapHelper.SetPixelRawAlpha : (BitmapHelper.SetPixelRawFunc)m_bitmapHelper.SetPixelRawNoAlpha; int destPixelSize = m_bitmapHelper.GetRawPixelSize(); const int scale = 3; for (int y = 0; y < 400; y++) { int sourceArrayIndex = y * stride; for (int j = 0; j < scale; j++) { int destArrayIndex = m_bitmapHelper.GetRawYIndex((y * scale) + j); for (int x = 0; x < 400; x++) { UInt32 color = framedata.get_uint32(sourceArrayIndex + x); for (int i = 0; i < scale; i++) { setPixelFunc(destArrayIndex, color); destArrayIndex += destPixelSize; } } } } m_bitmapHelper.Unlock(true); } #endif if (m_graphics != null) { m_graphics.DrawImage(m_bitmap, m_bitmapXOffset, m_bitmapYOffset); 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.overall_real_seconds + (double)video.overall_real_ticks / (double)tps; double final_emu_time = video.overall_emutime.as_double(); double average_speed_percentage = final_real_time == 0 ? 0 : 100 * final_emu_time / final_real_time; string total_time = (video.overall_emutime + new mame.attotime(0, mame.attotime.ATTOSECONDS_PER_SECOND / 2)).as_string(2); this.Text = string.Format("Emulator running... Avg Speed: {0:f2}% ({1} seconds) - speed_text: {2}", average_speed_percentage, total_time, video.speed_text()); } }
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 }