internal void PeriodicCallback() { ulong timer_overflow_tick_count = (ulong)((CounterOverflowValue - m_register) * 16); // check for interrupt enable if ((m_port05 & 0x20) != 0) { // check for overflow ulong ellapsed_period = m_tvc.GetTicksSince(m_interrupt_timestamp); if (ellapsed_period > timer_overflow_tick_count) { m_tvc.Interrupt.GenerateCursorSoundInterrupt(); m_interrupt_timestamp += (ellapsed_period / timer_overflow_tick_count) * timer_overflow_tick_count;// m_tvc.CPU.TotalTState;// (ellapsed_period / timer_overflow_tick_count+ 1) * timer_overflow_tick_count; //m_tvc.CPU.TotalTState;// ellapsed_period - timer_overflow_tick_count; } } }
/// <summary> /// Update TVC hardware keyboard matrix content /// </summary> private void UpdateKeyboardMatrix() { // do not update when injection is in progress if (m_keyboard_injection_pos >= 0) { return; } //////////////////////// // init keyboard matrix byte[] keyboard_matrix = new byte[KeyboardRowCount]; for (int i = 0; i < keyboard_matrix.Length; i++) { keyboard_matrix[i] = 0xff; } if (m_keyboard_injection_pos >= 0) { Key pressed_key; if (m_tvc.GetTicksSince(m_keyboard_injection_timestamp) > m_keyboard_injection_rate) { m_keyboard_injection_timestamp = m_tvc.GetCPUTicks(); m_keyboard_injection_pos++; if (m_keyboard_injection_pos >= m_keyboard_injection_string.Length) { m_keyboard_injection_pos = -1; } } if (m_keyboard_injection_pos >= 0) { pressed_key = (Key)Enum.Parse(typeof(Key), m_keyboard_injection_string.Substring(m_keyboard_injection_pos, 1), true); KeyMappingEntry windows_key = new KeyMappingEntry(pressed_key, ModifierKeys.None, 0, 0, KeyModifiers.None); if (m_key_mapping.Contains(windows_key)) { KeyMappingEntry entry = m_key_mapping[windows_key.GetHashCode()]; keyboard_matrix[entry.Row] &= (byte)(~(1 << entry.Column)); } } } else { ///////////////////////////////// // Add pressed keys to the matrix KeyModifiers modifiers = KeyModifiers.KeepAll; for (int i = 0; i < PressedKeyCount; i++) { if (m_pressed_keys[i] != Key.None) { KeyMappingEntry windows_key = new KeyMappingEntry(m_pressed_keys[i], Keyboard.Modifiers, 0, 0, KeyModifiers.None); if (m_key_mapping.Contains(windows_key)) { KeyMappingEntry entry = m_key_mapping[windows_key.GetHashCode()]; keyboard_matrix[entry.Row] &= (byte)(~(1 << entry.Column)); modifiers = entry.Modifiers; } } } //////////////////// // Handle modifiers // shift key if (m_shift_key != null) { if ((modifiers & KeyModifiers.AddShift) != 0) { keyboard_matrix[m_shift_key.Row] &= (byte)(~(1 << m_shift_key.Column)); } if ((modifiers & KeyModifiers.RemoveShift) != 0) { keyboard_matrix[m_shift_key.Row] |= (byte)(1 << m_shift_key.Column); } } // Ctrl shift key if (m_ctrl_key != null) { if ((modifiers & KeyModifiers.AddCtrl) != 0) { keyboard_matrix[m_ctrl_key.Row] &= (byte)(~(1 << m_ctrl_key.Column)); } if ((modifiers & KeyModifiers.RemoveCtrl) != 0) { keyboard_matrix[m_ctrl_key.Row] |= (byte)(1 << m_ctrl_key.Column); } } // Alt shift key if (m_alt_key != null) { if ((modifiers & KeyModifiers.AddAlt) != 0) { keyboard_matrix[m_alt_key.Row] &= (byte)(~(1 << m_alt_key.Column)); } if ((modifiers & KeyModifiers.RemoveAlt) != 0) { keyboard_matrix[m_alt_key.Row] |= (byte)(1 << m_alt_key.Column); } } } //////////////////////// // store keyboard matrix for (int i = 0; i < KeyboardRowCount; i++) { m_keyboard_matrix[i] = keyboard_matrix[i]; #if DEBUG_TVC_KEYBOARD Debug.Write(m_keyboard_matrix[i].ToString("x2") + " "); #endif } #if DEBUG_TVC_KEYBOARD Debug.WriteLine(""); #endif }