root/lang/ruby/CPU-Z80/trunk/lib/CPU/Z80/register16.rb @ 4473

Revision 4473, 1.1 kB (checked in by mrkn, 6 years ago)

lang/ruby/CPU-Z80: import.

  • Property svn:keywords set to Id
Line 
1# $Id$
2
3require 'CPU/Z80/register8'
4
5module CPU
6  module Z80
7    class Register16
8      MASK16 = 0xFFFF
9
10      def value
11        @high.value << 8 | @low.value
12      end
13
14      def value=(v)
15        @high.value = v >> 8
16        @low.value = v
17      end
18
19      def high; @high.value; end
20      def low;  @low.value;  end
21
22      def high=(v)
23        @high.value = v
24      end
25
26      def low=(v)
27        @low.value = v
28      end
29
30      # e.g. @hl = Register.new(:h, :l)
31      #
32      def initialize(names=nil, v=nil)
33        if names
34          high_name, low_name = names[0,2]
35          eval <<-END_OF_DEFINITION
36            def self.#{high_name}; self.high; end
37            def self.#{low_name}; self.low; end
38            def self.#{high_name}=(v); self.high = v; end
39            def self.#{low_name}=(v); self.low = v; end
40          END_OF_DEFINITION
41        end
42        @high = Register8.new
43        @low = Register8.new
44        self.value = v || 0
45      end
46    end
47  end
48end
49
50# Local Variables:
51# coding: utf-8
52# mode: ruby
53# ruby-indent-level: 2
54# ruby-indent-tabs-mode: nil
55# End:
Note: See TracBrowser for help on using the browser.