def with_each_mode
      begin
        orig = current_mode
      rescue
        orig = nil
      end
      modes.each do |_id, mode|
        self.current_mode = mode
        yield mode
      end
      self.current_mode = orig
    end
def with_each_mode
      begin
        orig = current_mode
      rescue
        orig = nil
      end
      modes.each do |_id, mode|
        self.current_mode = mode
        yield mode
      end
      self.current_mode = orig
    end
Executes the given block of code for each known chip mode, inside the block
 the current mode of the top level block will be set to the given mode.

 At the end of the block the current mode will be restored to whatever it
 was before entering the block.