Class: Retrograph::Easy::Logo

Inherits:
Object
  • Object
show all
Defined in:
lib/retrograph/easy/logo.rb

Constant Summary collapse

START_PATTERN =
1
LETTER_NAME_DATA =
(0...n_letter_patterns).map { |i|
  [ i + letter_pattern_offset, 0 ]
}.flatten.pack("C*")
PATTERN_DATA =
[letter_patterns, led_patterns].flatten.inject("") { |a, b| a + b }
CHARACTERS =
[
  0b00100010, # r
  0b01111110, # e
  0b00111010, # t
  0b00100010, # r
  0b00110011, # o
  0b01111101, # g
  0b00100010, # r
  0b01110111, # a
  0b01101110, # P
  0b00101011  # h
]
CHAR_BIT_MAPPINGS =
[
  [0, corner_pattern_offset, [[0b01000000, 5], [0b00001000, 3]]],
  [2, corner_pattern_offset, [[0b01000000, 5], [0b00000100, 2]]],
  [64, middle_pattern_offset, [[0b00100000, 3], [0b00001000, 2], [0b00000010, 1]]],
  [66, middle_pattern_offset, [[0b00100000, 3], [0b00000100, 1], [0b00000001, 0]]],
  [128, corner_pattern_offset, [[0b00010000, 3], [0b00000010, 1]]],
  [130, corner_pattern_offset, [[0b00010000, 3], [0b00000001, 0]]]
]

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Logo

Returns a new instance of Logo.



28
29
30
# File 'lib/retrograph/easy/logo.rb', line 28

def initialize(app)
  @app = app
end

Instance Method Details

#prepare_led_character(name_base) ⇒ Object



75
76
77
78
79
80
# File 'lib/retrograph/easy/logo.rb', line 75

def prepare_led_character(name_base)
  @app.write_vdu_byte(0x0800 + name_base + 3, 0b00100000)
  @app.write_vdu_byte(0x0800 + name_base + 67, 0b00100000)
  @app.write_vdu_byte(0x0800 + name_base + 129, 0b00010000)
  @app.write_vdu_byte(0x0800 + name_base + 131, 0b00110000)
end

#prepare_led_characters(name_base, count) ⇒ Object



68
69
70
71
72
73
# File 'lib/retrograph/easy/logo.rb', line 68

def prepare_led_characters(name_base, count)
  count.times do
    prepare_led_character(name_base)
    name_base += 4
  end
end

#showObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/retrograph/easy/logo.rb', line 32

def show
  @app.reset_vdu

  @app.vdu_mode 0x7

  # setup palette
  @app.palette_entry_rgb 0, 0, 0, 0
  @app.palette_entry_rgb 1, 255, 0, 0

  # setup patterns
  @app.tile_pattern_4bit(0x0000, START_PATTERN, PATTERN_DATA)

  num_characters = CHARACTERS.size

  start_row = (28 - 4) / 2 - 2
  start_col = (32 - (num_characters * 2)) / 2
  name_base = (start_col + start_row * 32) * 2

  # setup name table
  @app.write_vdu(0x0800 + name_base, LETTER_NAME_DATA)
  name_base += 64
  prepare_led_characters(name_base, num_characters)

  # start display loop
  characters = [0] * num_characters
  delay = 9
  for revealed in 0..num_characters
    @app.each_of_n_frames(delay) do
      characters.map! { rand(127) + 1 }
      characters[0, revealed] = CHARACTERS[0, revealed]
      show_led_characters(name_base, characters)
    end
    delay = 1
  end
end

#show_led_character(name_base, c) ⇒ Object



89
90
91
92
93
94
95
96
# File 'lib/retrograph/easy/logo.rb', line 89

def show_led_character(name_base, c)
  for (name_offset, index, mappings) in CHAR_BIT_MAPPINGS
    for (mask, shift) in mappings
      index += (c & mask) >> shift
    end
    @app.write_vdu_byte(0x0800 + name_base + name_offset, index)
  end
end

#show_led_characters(name_base, cs) ⇒ Object



82
83
84
85
86
87
# File 'lib/retrograph/easy/logo.rb', line 82

def show_led_characters(name_base, cs)
  cs.each do |c|
    show_led_character(name_base, c)
    name_base += 4
  end
end