Class: Badline::Keyboard
- Inherits:
-
Object
- Object
- Badline::Keyboard
- Includes:
- IntegerHelper
- Defined in:
- lib/badline/keyboard.rb
Instance Attribute Summary collapse
-
#keys ⇒ Object
readonly
Returns the value of attribute keys.
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
Instance Method Summary collapse
-
#initialize ⇒ Keyboard
constructor
A new instance of Keyboard.
- #press(key) ⇒ Object
- #read_a(_port_a, _port_b) ⇒ Object
- #read_b(port_a, _port_b) ⇒ Object
- #release(key) ⇒ Object
Methods included from IntegerHelper
#bcd, #bcd_to_i, #format16, #format8, #high_byte, #low_byte, #signed_int8, #uint16
Constructor Details
#initialize ⇒ Keyboard
Returns a new instance of Keyboard.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/badline/keyboard.rb', line 9 def initialize @keys = [] @matrix = [ %i[delete return cursor_h f7 f1 f3 cursor_v], %i[3 w a 4 z s e lshift], %i[5 r d 6 c f t x], %i[7 y g 8 b h u v], %i[9 i j 0 m k o n], %i[+ p l - . : @ ,], %i[£ * ; clr_home rshift = up /], %i[1 left control 2 space cbm q run_stop] ] end |
Instance Attribute Details
#keys ⇒ Object (readonly)
Returns the value of attribute keys.
7 8 9 |
# File 'lib/badline/keyboard.rb', line 7 def keys @keys end |
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
7 8 9 |
# File 'lib/badline/keyboard.rb', line 7 def matrix @matrix end |
Instance Method Details
#press(key) ⇒ Object
24 25 26 |
# File 'lib/badline/keyboard.rb', line 24 def press(key) @keys << key if valid_key?(key) end |
#read_a(_port_a, _port_b) ⇒ Object
28 29 30 |
# File 'lib/badline/keyboard.rb', line 28 def read_a(_port_a, _port_b) 0xff end |
#read_b(port_a, _port_b) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/badline/keyboard.rb', line 32 def read_b(port_a, _port_b) return 0xff unless keys.any? output = 0xff matrix.each_with_index do |row, a| next unless port_a[a].zero? row.each_with_index do |key, b| output -= (1 << b) if keys.include?(key) end end output end |
#release(key) ⇒ Object
48 49 50 |
# File 'lib/badline/keyboard.rb', line 48 def release(key) @keys.reject! { |k| k == key } end |