Class: Badline::CIA::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/badline/cia/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control) ⇒ Timer

Returns a new instance of Timer.



9
10
11
12
13
14
15
16
17
18
# File 'lib/badline/cia/timer.rb', line 9

def initialize(control)
  @control = control
  @counter = @latch = 0x0
  @pipe = 0
  @load_delay = 0
  @reload = false
  @underflowed = false
  @oneshot_linger = 0
  @toggle = true
end

Instance Attribute Details

#controlObject (readonly)

Returns the value of attribute control.



7
8
9
# File 'lib/badline/cia/timer.rb', line 7

def control
  @control
end

#counterObject

Returns the value of attribute counter.



6
7
8
# File 'lib/badline/cia/timer.rb', line 6

def counter
  @counter
end

#latchObject

Returns the value of attribute latch.



6
7
8
# File 'lib/badline/cia/timer.rb', line 6

def latch
  @latch
end

#underflowedObject (readonly)

Returns the value of attribute underflowed.



7
8
9
# File 'lib/badline/cia/timer.rb', line 7

def underflowed
  @underflowed
end

Instance Method Details

#cycle!(feed, pulse) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/badline/cia/timer.rb', line 24

def cycle!(feed, pulse)
  return @counter -= 1 if feed && pulse && steady?

  if (@pipe | @load_delay).zero? && !@reload
    @pipe = 0b10 if feed && started?
    return
  end
  run_tick(feed, pulse)
end

#run_tick(feed, pulse) ⇒ Object



34
35
36
37
38
# File 'lib/badline/cia/timer.rb', line 34

def run_tick(feed, pulse)
  @underflowed = false
  @oneshot_linger -= 1 if @oneshot_linger.positive?
  tick(feed && started?, pulse)
end

#toggle?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/badline/cia/timer.rb', line 20

def toggle?
  @toggle
end

#write_control(value) ⇒ Object



40
41
42
43
44
45
# File 'lib/badline/cia/timer.rb', line 40

def write_control(value)
  @toggle = true if value.anybits?(0x01) && !started?
  @oneshot_linger = 2 if control.run_mode? && value.nobits?(0x08)
  control.value = value & ~0x10
  @load_delay = 3 if value.anybits?(0x10)
end

#write_latch_high(value) ⇒ Object



51
52
53
54
# File 'lib/badline/cia/timer.rb', line 51

def write_latch_high(value)
  @latch = (value << 8) | (@latch & 0xff)
  @counter = @latch unless started?
end

#write_latch_low(value) ⇒ Object



47
48
49
# File 'lib/badline/cia/timer.rb', line 47

def write_latch_low(value)
  @latch = (@latch & 0xff00) | value
end