2015-08-21 19:07:27 +02:00
|
|
|
require_relative "object_view"
|
2015-07-09 14:23:36 +02:00
|
|
|
|
2015-08-21 19:07:27 +02:00
|
|
|
class RegistersView < ListView
|
2015-07-09 14:23:36 +02:00
|
|
|
|
2015-08-21 19:07:27 +02:00
|
|
|
def initialize interpreter
|
|
|
|
@interpreter = interpreter
|
|
|
|
@interpreter.register_event(:register_changed, self)
|
|
|
|
kids = []
|
|
|
|
@interpreter.registers.each do |reg , val|
|
|
|
|
kids << ValueView.new( val )
|
|
|
|
end
|
|
|
|
super(kids)
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2015-08-22 19:28:09 +02:00
|
|
|
super( "div.registers_view" )
|
2015-08-23 02:16:32 +02:00
|
|
|
@element.children.each_with_index do |reg, index|
|
2015-08-22 01:37:15 +02:00
|
|
|
elem = div("div.register_view")
|
2015-08-21 19:07:27 +02:00
|
|
|
wrap_node_with reg , elem
|
2015-07-09 14:23:36 +02:00
|
|
|
end
|
2015-08-22 01:37:15 +02:00
|
|
|
@element
|
2015-08-21 19:07:27 +02:00
|
|
|
end
|
|
|
|
|
2018-04-04 16:14:33 +02:00
|
|
|
def register_changed( reg , old , value )
|
2015-08-21 19:07:27 +02:00
|
|
|
reg = reg.symbol unless reg.is_a? Symbol
|
2015-08-22 02:23:53 +02:00
|
|
|
index = reg.to_s[1 .. -1 ].to_i
|
2018-04-03 15:48:45 +02:00
|
|
|
has = Risc.machine.objects[value.object_id]
|
2015-11-04 11:20:44 +01:00
|
|
|
if( has )
|
2018-04-03 15:48:45 +02:00
|
|
|
if has.is_a?(Risc::Label)
|
2015-11-04 11:20:44 +01:00
|
|
|
swap = ValueView.new "Label: #{has.name}"
|
|
|
|
else
|
|
|
|
swap = ObjectView.new( value , @interpreter , 16 - index )
|
|
|
|
end
|
2015-08-22 02:23:53 +02:00
|
|
|
else
|
|
|
|
swap = ValueView.new value
|
|
|
|
end
|
|
|
|
replace_at index , swap
|
2015-08-23 02:16:32 +02:00
|
|
|
# @elements[index].style["z-index"] = -index
|
2015-08-22 02:23:53 +02:00
|
|
|
end
|
|
|
|
|
2015-07-09 14:23:36 +02:00
|
|
|
end
|
2015-08-24 01:49:41 +02:00
|
|
|
|
|
|
|
class ValueView < ElementView
|
|
|
|
|
|
|
|
def initialize value
|
|
|
|
@value = value
|
|
|
|
end
|
|
|
|
|
|
|
|
def draw
|
2018-04-04 16:14:33 +02:00
|
|
|
li = div("li")
|
|
|
|
li << div("span", @value)
|
|
|
|
@element = div("ul.nav!") << li
|
2015-08-24 01:49:41 +02:00
|
|
|
end
|
|
|
|
end
|