Class: Remian::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/remian/control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ Control

Returns a new instance of Control.



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/remian/control.rb', line 20

def initialize data, options = {}
  @options = option_defaults.merge options

  @registers = {address: nil}
  @clock = Clock.new @options[:clock_speed]
  @decoder = Decoder.new

  @memory = Memory.new @options[:memory_size]
  @memory.write_data data

  @instruction_set = InstructionSet.new @memory, @registers
end

Instance Attribute Details

#clockObject

Returns the value of attribute clock.



14
15
16
# File 'lib/remian/control.rb', line 14

def clock
  @clock
end

#decoderObject

Returns the value of attribute decoder.



16
17
18
# File 'lib/remian/control.rb', line 16

def decoder
  @decoder
end

#instruction_setObject

Returns the value of attribute instruction_set.



18
19
20
# File 'lib/remian/control.rb', line 18

def instruction_set
  @instruction_set
end

#memoryObject

Returns the value of attribute memory.



15
16
17
# File 'lib/remian/control.rb', line 15

def memory
  @memory
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/remian/control.rb', line 13

def options
  @options
end

#registersObject

Returns the value of attribute registers.



17
18
19
# File 'lib/remian/control.rb', line 17

def registers
  @registers
end

Instance Method Details

#start(start_address = 1) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/remian/control.rb', line 33

def start start_address = 1
  @registers[:address] = start_address

  while @clock.tick_delay
    cycle
  end
end