Example #1
0
        /*-------------------------------------------------
        *   frame_update - looks through pressed
        *   input as per events pushed our way and posts
        *   corresponding IPT_UI_* events
        *  -------------------------------------------------*/
        void frame_update(running_machine machine)
        {
            /* update the state of all the UI keys */
            for (ioport_type code = (ioport_type)(ioport_type.IPT_UI_FIRST + 1); code < ioport_type.IPT_UI_LAST; ++code)
            {
                bool pressed = machine.ioport().type_pressed(code);
                if (!pressed || m_seqpressed[(int)code] != SEQ_PRESSED_RESET)
                {
                    m_seqpressed[(int)code] = pressed ? (byte)1 : (byte)0;
                }
            }

            // perform mouse hit testing
            ioport_field mouse_field = m_current_mouse_down ? find_mouse_field() : null;

            if (m_current_mouse_field != mouse_field)
            {
                // clear the old field if there was one
                if (m_current_mouse_field != null)
                {
                    m_current_mouse_field.set_value(0);
                }

                // set the new field if it exists and isn't already being pressed
                if (mouse_field != null && !mouse_field.digital_value())
                {
                    mouse_field.set_value(1);
                }

                // update internal state
                m_current_mouse_field = mouse_field;
            }
        }
Example #2
0
        //void internal_post(char32_t ch);


        //-------------------------------------------------
        //  timer - timer callback to keep things flowing
        //  when posting a string of characters
        //-------------------------------------------------
        void timer(object ptr, int param)
        {
            if (m_queue_chars != null)
            {
                // the driver has a queue_chars handler
                while (!empty() && m_queue_chars(m_buffer, m_bufbegin, 1) != 0)
                {
                    m_bufbegin = (m_bufbegin + 1) % (UInt32)m_buffer.size();
                    if (m_current_rate != attotime.zero)
                    {
                        break;
                    }
                }
            }
            else
            {
                // the driver does not have a queue_chars handler

                // loop through this character's component codes
                keycode_map_entry code = find_code(m_buffer[(int)m_bufbegin]);
                bool advance;
                if (code != null)
                {
                    do
                    {
                        assert(m_fieldnum < code.field.Length);

                        ioport_field field = code.field[m_fieldnum];
                        if (field != null)
                        {
                            // special handling for toggle fields
                            if (!field.live().toggle)
                            {
                                field.set_value(!m_status_keydown ? (UInt32)1 : 0);
                            }
                            else if (!m_status_keydown)
                            {
                                field.set_value(!field.digital_value() ? (UInt32)1 : 0);
                            }
                        }
                    }while (code.field[m_fieldnum] != null && (++m_fieldnum < code.field.Length) && m_status_keydown);
                    advance = (m_fieldnum >= code.field.Length) || code.field[m_fieldnum] == null;
                }
                else
                {
                    advance = true;
                }

                if (advance)
                {
                    m_fieldnum       = 0;
                    m_status_keydown = !m_status_keydown;

                    // proceed to next character when keydown expires
                    if (!m_status_keydown)
                    {
                        m_bufbegin = (m_bufbegin + 1) % (UInt32)m_buffer.size();
                    }
                }
            }

            // need to make sure timerproc is called again if buffer not empty
            if (!empty())
            {
                m_timer.adjust(choose_delay(m_buffer[(int)m_bufbegin]));
            }
        }