Пример #1
0
        // item management
        //-------------------------------------------------
        //  add_item - add a new item to an input device
        //-------------------------------------------------
        public input_item_id add_item(string name, input_item_id itemid, item_get_state_func getstate, object internal_obj = null)
        {
            if (machine().phase() != machine_phase.INIT)
            {
                throw new emu_fatalerror("Can only call input_device::add_item at init time!");
            }

            assert(itemid > input_item_id.ITEM_ID_INVALID && itemid < input_item_id.ITEM_ID_MAXIMUM);
            assert(getstate != null);

            // if we have a generic ID, pick a new internal one
            input_item_id originalid = itemid;

            if (itemid >= input_item_id.ITEM_ID_OTHER_SWITCH && itemid <= input_item_id.ITEM_ID_OTHER_AXIS_RELATIVE)
            {
                for (itemid = (input_item_id)(input_item_id.ITEM_ID_MAXIMUM + 1); itemid <= input_item_id.ITEM_ID_ABSOLUTE_MAXIMUM; ++itemid)
                {
                    if (m_item[(int)itemid] == null)
                    {
                        break;
                    }
                }
            }

            assert(itemid <= input_item_id.ITEM_ID_ABSOLUTE_MAXIMUM);

            // make sure we don't have any overlap
            assert(m_item[(int)itemid] == null);

            // determine the class and create the appropriate item class
            switch (m_manager.device_class(devclass()).standard_item_class(originalid))
            {
            case input_item_class.ITEM_CLASS_SWITCH:
                m_item[(int)itemid] = new input_device_switch_item(this, name, internal_obj, itemid, getstate);
                break;

            case input_item_class.ITEM_CLASS_RELATIVE:
                m_item[(int)itemid] = new input_device_relative_item(this, name, internal_obj, itemid, getstate);
                break;

            case input_item_class.ITEM_CLASS_ABSOLUTE:
                m_item[(int)itemid] = new input_device_absolute_item(this, name, internal_obj, itemid, getstate);
                break;

            default:
                m_item[(int)itemid] = null;
                assert(false);
                break;
            }

            // assign the new slot and update the maximum
            m_maxitem = (input_item_id)std.max((int)m_maxitem, (int)itemid);
            return(itemid);
        }
Пример #2
0
        bool m_lightgun_reload_button;                                                                        // lightgun reload hack


        // construction/destruction
        //-------------------------------------------------
        //  input_device - constructor
        //-------------------------------------------------
        protected input_device(input_manager manager, string name, string id, object internalobj)
        {
            m_manager                = manager;
            m_name                   = name;
            m_id                     = id;
            m_devindex               = -1;
            m_maxitem                = 0;
            m_internal               = internalobj;
            m_steadykey_enabled      = manager.machine().options().steadykey();
            m_lightgun_reload_button = manager.machine().options().offscreen_reload();
        }
Пример #3
0
        // misc helpers

        //-------------------------------------------------
        //  standard_item_class - return the class of a
        //  standard item
        //-------------------------------------------------
        public input_item_class standard_item_class(input_item_id itemid)
        {
            // most everything standard is a switch, apart from the axes
            if (itemid == input_item_id.ITEM_ID_OTHER_SWITCH || itemid < input_item_id.ITEM_ID_XAXIS || (itemid > input_item_id.ITEM_ID_SLIDER2 && itemid < input_item_id.ITEM_ID_ADD_ABSOLUTE1))
            {
                return(input_item_class.ITEM_CLASS_SWITCH);
            }

            // standard mouse axes are relative
            else if (m_devclass == input_device_class.DEVICE_CLASS_MOUSE || itemid == input_item_id.ITEM_ID_OTHER_AXIS_RELATIVE || (itemid >= input_item_id.ITEM_ID_ADD_RELATIVE1 && itemid <= input_item_id.ITEM_ID_ADD_RELATIVE16))
            {
                return(input_item_class.ITEM_CLASS_RELATIVE);
            }

            // all other standard axes are absolute
            else
            {
                return(input_item_class.ITEM_CLASS_ABSOLUTE);
            }
        }
Пример #4
0
        // helpers
        //-------------------------------------------------
        //  apply_steadykey - apply steadykey option
        //-------------------------------------------------
        public void apply_steadykey()
        {
            // ignore if not enabled
            if (!steadykey_enabled())
            {
                return;
            }

            // update the state of all the keys and see if any changed state
            bool anything_changed = false;

            for (input_item_id itemid = input_item_id.ITEM_ID_FIRST_VALID; itemid <= maxitem(); ++itemid)
            {
                input_device_item itm = item(itemid);
                if (itm != null && itm.itemclass() == input_item_class.ITEM_CLASS_SWITCH)
                {
                    if (((input_device_switch_item)itm).steadykey_changed())
                    {
                        anything_changed = true;
                    }
                }
            }

            // if the keyboard state is stable, flush the current state
            if (!anything_changed)
            {
                for (input_item_id itemid = input_item_id.ITEM_ID_FIRST_VALID; itemid <= maxitem(); ++itemid)
                {
                    input_device_item itm = item(itemid);
                    if (itm != null && itm.itemclass() == input_item_class.ITEM_CLASS_SWITCH)
                    {
                        ((input_device_switch_item)itm).steadykey_update_to_current();
                    }
                }
            }
        }
Пример #5
0
        public override input_code poll()
        {
            // iterate over device classes and devices, skipping disabled classes
            for (input_device_class classno = input_device_class.DEVICE_CLASS_FIRST_VALID; input_device_class.DEVICE_CLASS_LAST_VALID >= classno; ++classno)
            {
                input_class devclass = m_manager.device_class(classno);
                if (!devclass.enabled())
                {
                    continue;
                }

                for (int devnum = 0; devclass.maxindex() >= devnum; ++devnum)
                {
                    // fetch the device; ignore if nullptr
                    input_device device = devclass.device(devnum);
                    if (device == null)
                    {
                        continue;
                    }

                    // iterate over items within each device
                    for (input_item_id itemid = input_item_id.ITEM_ID_FIRST_VALID; device.maxitem() >= itemid; ++itemid)
                    {
                        input_device_item item = device.item(itemid);
                        if (item == null)
                        {
                            continue;
                        }

                        input_code code = item.code();
                        if (item.itemclass() == input_item_class.ITEM_CLASS_SWITCH)
                        {
                            // item is natively a switch, poll it
                            if (code_pressed_once(code, true))
                            {
                                return(code);
                            }
                            else
                            {
                                continue;
                            }
                        }

                        throw new emu_unimplemented();
#if false
                        var memory = std.lower_bound(
                            m_axis_memory,
                            item,
                            (std.pair <input_device_item, s32> x, input_device_item y) => { return(x.first < y); });
                        if ((m_axis_memory.end() == memory) || (item != memory.first))  //if ((m_axis_memory.end() == memory) || (item != memory->first))
                        {
                            continue;
                        }

                        // poll axes digitally
                        bool moved = item.check_axis(code.item_modifier(), memory.second);
                        code.set_item_class(input_item_class.ITEM_CLASS_SWITCH);
                        if ((classno == input_device_class.DEVICE_CLASS_JOYSTICK) && (code.item_id() == input_item_id.ITEM_ID_XAXIS))
                        {
                            // joystick X axis - check with left/right modifiers
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_LEFT);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_RIGHT);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                        }
                        else if ((classno == input_device_class.DEVICE_CLASS_JOYSTICK) && (code.item_id() == input_item_id.ITEM_ID_YAXIS))
                        {
                            // if this is a joystick Y axis, check with up/down modifiers
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_UP);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_DOWN);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                        }
                        else
                        {
                            // any other axis, check with pos/neg modifiers
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_POS);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                            code.set_item_modifier(input_item_modifier.ITEM_MODIFIER_NEG);
                            if (code_pressed_once(code, moved))
                            {
                                return(code);
                            }
                        }
#endif
                    }
                }
            }

            // if nothing, return an invalid code
            return(input_code.INPUT_CODE_INVALID);
        }
Пример #6
0
        int m_oldkey;               // old live state


        // construction/destruction
        //-------------------------------------------------
        //  input_device_switch_item - constructor
        //-------------------------------------------------
        public input_device_switch_item(input_device device, string name, object internalobj, input_item_id itemid, item_get_state_func getstate)
            : base(device, name, internalobj, itemid, getstate, input_item_class.ITEM_CLASS_SWITCH)
        {
            m_steadykey = 0;
            m_oldkey    = 0;
        }
Пример #7
0
 public input_device_item item(input_item_id index)
 {
     return(m_item[(int)index]);
 }
Пример #8
0
        s32 m_memory;               // "memory" value, to remember where we started during polling


        // construction/destruction
        //-------------------------------------------------
        //  input_device_item - constructor
        //-------------------------------------------------
        protected input_device_item(input_device device, string name, object internalobj, input_item_id itemid, item_get_state_func getstate, input_item_class itemclass)
        {
            m_device    = device;
            m_name      = name;
            m_internal  = internalobj;
            m_itemid    = itemid;
            m_itemclass = itemclass;
            m_getstate  = getstate;
            m_current   = 0;
            m_memory    = 0;


            // use a standard token name for know item IDs
            string standard_token = manager().standard_token(itemid);

            if (standard_token != null)
            {
                m_token = standard_token;
            }
            // otherwise, create a tokenized name
            else
            {
                m_token = name;
                m_token = m_token.ToUpper();
                m_token = m_token.Replace(" ", "");  //strdelchr(m_token, ' ');
                m_token = m_token.Replace("_", "");  //strdelchr(m_token, '_');
            }
        }
Пример #9
0
 // construction/destruction
 //-------------------------------------------------
 //  input_device_absolute_item - constructor
 //-------------------------------------------------
 public input_device_absolute_item(input_device device, string name, object internalobj, input_item_id itemid, item_get_state_func getstate)
     : base(device, name, internalobj, itemid, getstate, input_item_class.ITEM_CLASS_ABSOLUTE)
 {
 }
Пример #10
0
 // construction/destruction
 //-------------------------------------------------
 //  input_device_relative_item - constructor
 //-------------------------------------------------
 public input_device_relative_item(input_device device, string name, object internalobj, input_item_id itemid, item_get_state_func getstate)
     : base(device, name, internalobj, itemid, getstate, input_item_class.ITEM_CLASS_RELATIVE)
 {
 }
Пример #11
0
        public override void init(running_machine machine)
        {
            // call our parent
            base.init(machine);

            set_verbose(true);

            string stemp;
            osd_options_WinForms options = (osd_options_WinForms)machine.options();

            // determine if we are benchmarking, and adjust options appropriately
            int bench = options.bench();
            if (bench > 0)
            {
                options.set_value(emu_options.OPTION_THROTTLE, 0, OPTION_PRIORITY_MAXIMUM);
                options.set_value(osd_options.OSDOPTION_SOUND, "none", OPTION_PRIORITY_MAXIMUM);
                options.set_value(osd_options.OSDOPTION_VIDEO, "none", OPTION_PRIORITY_MAXIMUM);
                options.set_value(emu_options.OPTION_SECONDS_TO_RUN, bench, OPTION_PRIORITY_MAXIMUM);
            }

            // determine if we are profiling, and adjust options appropriately
            int profile = options.profile();
            if (profile > 0)
            {
                options.set_value(emu_options.OPTION_THROTTLE, 0, OPTION_PRIORITY_MAXIMUM);
                options.set_value(osd_options.OSDOPTION_NUMPROCESSORS, 1, OPTION_PRIORITY_MAXIMUM);
            }

#if false
            // thread priority
            if ((machine.debug_flags_get() & running_machine.DEBUG_FLAG_OSD_ENABLED) == 0)
                SetThreadPriority(GetCurrentThread(), options.priority());
#endif

            // get number of processors
            stemp = options.numprocessors();

#if false
            osd_num_processors = 0;

            if (stemp != "auto")
            {
                osd_num_processors = Convert.ToInt32(stemp);
                if (osd_num_processors < 1)
                {
                    osdcore_global.m_osdcore.osd_printf_warning("Warning: numprocessors < 1 doesn't make much sense. Assuming auto ...\n");
                    osd_num_processors = 0;
                }
            }
#endif

            // initialize the subsystems
            init_subsystems();

#if false
            // notify listeners of screen configuration
            string tempstring;
            for (win_window_info info = win_window_list; info != null; info = info.m_next)
            {
                string tmp = utf8_from_tstring(info.m_monitor.info.szDevice);
                string tempstring = string.Format("Orientation({0})", tmp);
                output_set_value(tempstring, info.m_targetorient);
                //osd_free(tmp);
            }
#endif


            // hook up the debugger log
            if (options.oslog())
                machine.add_logerror_callback(osdcore_interface.osd_printf_debug);


#if false
            // crank up the multimedia timer resolution to its max
            // this gives the system much finer timeslices
            timeresult = timeGetDevCaps(&timecaps, sizeof(timecaps));
            if (timeresult == TIMERR_NOERROR)
                timeBeginPeriod(timecaps.wPeriodMin);
#endif

#if false
            // if a watchdog thread is requested, create one
            int watchdog = options.watchdog();
            if (watchdog != 0)
            {
                watchdog_reset_event = CreateEvent(NULL, FALSE, FALSE, NULL);
                emucore_global.assert_always(watchdog_reset_event != null, "Failed to create watchdog reset event");
                watchdog_exit_event = CreateEvent(NULL, TRUE, FALSE, NULL);
                emucore_global.assert_always(watchdog_exit_event != null, "Failed to create watchdog exit event");
                watchdog_thread = CreateThread(NULL, 0, watchdog_thread_entry, (LPVOID)(FPTR)watchdog, 0, NULL);
                emucore_global.assert_always(watchdog_thread != null, "Failed to create watchdog thread");
            }
#endif

#if false
            // create and start the profiler
            if (profile > 0)
            {
                profiler = new sampling_profiler(1000, profile - 1));
                profiler.start();
            }
#endif

#if false
            // initialize sockets
            win_init_sockets();
#endif

#if false
            // note the existence of a machine
            g_current_machine = &machine; 
#endif


            /////////////////////////////////////////////
            // custom code below

            validity_checker valid = new validity_checker(machine.options());
            valid.set_validate_all(true);
            string sysname = machine.options().system_name();
            bool result = valid.check_all_matching(string.IsNullOrEmpty(sysname) ? "*" : sysname);
            if (!result)
                throw new emu_fatalerror(main_global.EMU_ERR_FAILED_VALIDITY, "Validity check failed ({0} errors, {1} warnings in total)\n", valid.errors(), valid.warnings());
            valid.Dispose();

            /**
             *  Save away the machine, we'll need it in osd_customize_input_type_list
             **/
            //g_state.machine = machine;
    
            /**
             * Create the render_target that tells MAME the rendering parameters it
             * will use.
             **/
            m_target = machine.render().target_alloc();


            /**
             * Have this target hold every view since we only support one target
             **/
            m_target.set_view(m_target.configured_view("auto", 0, 1));

            /**
             * Set render target bounds to 10000 x 10000 and allow the callback to
             * scale that to whatever they want.
             **/
            //m_target.set_bounds(640, 480, 1.0f);
            m_target.set_bounds(400, 400, 1.0f);


            screenbufferptr = new RawBufferPointer(screenbuffer);


            {
                keyboard_state = new intref[(int)input_item_id.ITEM_ID_ABSOLUTE_MAXIMUM];
                for (int i = 0; i < (int)input_item_id.ITEM_ID_ABSOLUTE_MAXIMUM; i++)
                    keyboard_state[i] = new intref();

                input_device keyboard_device;
                keyboard_device = machine.input().device_class(input_device_class.DEVICE_CLASS_KEYBOARD).add_device("Keyboard", "Keyboard0");
                if (keyboard_device == null)
                    throw new emu_fatalerror("osd_interface.init() - FAILED - add_device() failed\n");

                foreach (var entry in mameForm.Form1.keymap)
                {
                    string defname = entry.Key.ToString();  //string.Format("Scan{0}", count++);
                    input_item_id itemid = entry.Value;
                    keyboard_device.add_item(defname, itemid, keyboard_get_state, keyboard_state[(int)itemid]);
                }
            }


            {
                mouse_axis_state = new intref[2];
                for (int i = 0; i < 2; i++)
                    mouse_axis_state[i] = new intref();

                input_device mouse_device;
                mouse_device = machine.input().device_class(input_device_class.DEVICE_CLASS_MOUSE).add_device("Mouse", "Mouse0");
                if (mouse_device == null)
                    throw new emu_fatalerror("osd_interface.init() - FAILED - add_device() failed\n");

                string defname;
                defname = string.Format("X {0}", mouse_device.name());
                mouse_device.add_item(defname, input_item_id.ITEM_ID_XAXIS, mouse_axis_get_state, mouse_axis_state[0]);
                defname = string.Format("Y {0}", mouse_device.name());
                mouse_device.add_item(defname, input_item_id.ITEM_ID_YAXIS, mouse_axis_get_state, mouse_axis_state[1]);


                mouse_button_state = new intref[5];
                for (int i = 0; i < 5; i++)
                    mouse_button_state[i] = new intref();

                defname = string.Format("B1");
                mouse_device.add_item(defname, input_item_id.ITEM_ID_BUTTON1, mouse_button_get_state, mouse_button_state[0]);
                defname = string.Format("B2");
                mouse_device.add_item(defname, input_item_id.ITEM_ID_BUTTON2, mouse_button_get_state, mouse_button_state[1]);
                defname = string.Format("B3");
                mouse_device.add_item(defname, input_item_id.ITEM_ID_BUTTON3, mouse_button_get_state, mouse_button_state[2]);
                defname = string.Format("B4");
                mouse_device.add_item(defname, input_item_id.ITEM_ID_BUTTON4, mouse_button_get_state, mouse_button_state[3]);
                defname = string.Format("B5");
                mouse_device.add_item(defname, input_item_id.ITEM_ID_BUTTON5, mouse_button_get_state, mouse_button_state[4]);
            }


            //System.Windows.Forms.Application.Run(new mameForm.Form1());
            //System.Windows.Forms.Form mainForm = new mameForm.Form1();
            //mainForm.FormClosed += (_sender, _args) => { System.Windows.Forms.Application.ExitThread(); };
            //mainForm.Show();

            //Console.WriteLine("After Show()");
        }