Class: DCPU16::Debugger
- Inherits:
-
Object
- Object
- DCPU16::Debugger
- Defined in:
- lib/dcpu16/debugger.rb
Instance Attribute Summary collapse
-
#cpu ⇒ Object
readonly
Returns the value of attribute cpu.
-
#screen ⇒ Object
readonly
Returns the value of attribute screen.
Instance Method Summary collapse
-
#clear_screen ⇒ Object
Clears screen for output.
-
#initialize(dump = [], options = {}) ⇒ Debugger
constructor
A new instance of Debugger.
- #run ⇒ Object
-
#update(cpu) ⇒ Object
Observer.
Constructor Details
#initialize(dump = [], options = {}) ⇒ Debugger
Returns a new instance of Debugger.
4 5 6 7 8 9 10 11 |
# File 'lib/dcpu16/debugger.rb', line 4 def initialize(dump = [], = {}) @cpu = DCPU16::CPU.new(dump) @screen = DCPU16::Screen.new(@cpu.memory) @update_every = [:update_every] || 100000 @step_mode = false || [:step_mode] @cpu.add_observer(self) end |
Instance Attribute Details
#cpu ⇒ Object (readonly)
Returns the value of attribute cpu.
3 4 5 |
# File 'lib/dcpu16/debugger.rb', line 3 def cpu @cpu end |
#screen ⇒ Object (readonly)
Returns the value of attribute screen.
3 4 5 |
# File 'lib/dcpu16/debugger.rb', line 3 def screen @screen end |
Instance Method Details
#clear_screen ⇒ Object
Clears screen for output
52 53 54 |
# File 'lib/dcpu16/debugger.rb', line 52 def clear_screen print @screen.to_s end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dcpu16/debugger.rb', line 13 def run at_exit do print @screen puts @cpu.to_s end begin if @step_mode @update_every = nil while a = $stdin.gets a = a.to_i a = (@last_step_count || 1) if a < 1 @last_step_count = a @cpu.step(a) print @screen print @cpu.to_s end else clear_screen @cpu.run end rescue DCPU16::Instructions::Reserved => e print @cpu.to_s end end |
#update(cpu) ⇒ Object
Observer
41 42 43 44 45 46 47 48 49 |
# File 'lib/dcpu16/debugger.rb', line 41 def update(cpu) @counter ||= 0 if @update_every && @counter > @update_every @counter = 0 clear_screen print @cpu.to_s end @counter += 1 end |