Ejemplo n.º 1
0
        protected bool code_pressed_once(input_code code, bool moved)
        {
            // look for the code in the memory
            bool pressed = m_manager.code_pressed(code);
            var  found   = std.lower_bound(m_switch_memory, code); //auto const found(std::lower_bound(m_switch_memory.begin(), m_switch_memory.end(), code));

            if ((-1 != found) && (m_switch_memory[found] == code)) //if ((m_switch_memory.end() != found) && (*found == code))
            {
                // if no longer pressed, clear entry
                if (!pressed)
                {
                    m_switch_memory.erase(found);
                }

                // always return false
                return(false);
            }

            // if we get here, we were not previously pressed; if still not pressed, return false
            if (!pressed || !moved)
            {
                return(false);
            }

            // otherwise, add the code to the memory and return true
            m_switch_memory.emplace(found, code);
            return(true);
        }
Ejemplo n.º 2
0
        //-------------------------------------------------
        //  unicode_to_string - obtain a string
        //  representation of a given code; used for
        //  logging and debugging
        //-------------------------------------------------
        string unicode_to_string(char32_t ch)
        {
            string buffer = "";

            switch (ch)
            {
            // check some magic values
            case '\0':  buffer = "\\0";      break;

            case '\r':  buffer = "\\r";      break;

            case '\n':  buffer = "\\n";      break;

            case '\t':  buffer = "\\t";      break;

            default:
                // seven bit ASCII is easy
                if (ch >= 32 && ch < 128)
                {
                    //char temp[2] = { char(ch), 0 };
                    buffer += (char)ch;
                }
                else if (ch >= ioport_global.UCHAR_MAMEKEY_BEGIN)
                {
                    // try to obtain a codename with code_name(); this can result in an empty string
                    input_code code = new input_code(input_device_class.DEVICE_CLASS_KEYBOARD, 0, input_item_class.ITEM_CLASS_SWITCH, input_item_modifier.ITEM_MODIFIER_NONE, (input_item_id)(ch - ioport_global.UCHAR_MAMEKEY_BEGIN));
                    buffer = machine().input().code_name(code);
                }

                // did we fail to resolve? if so, we have a last resort
                if (buffer.empty())
                {
                    buffer = string.Format("U+{0}", (UInt32)ch);      // U+%04X
                }
                break;
            }

            return(buffer);
        }
Ejemplo n.º 3
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);
        }