Z80/Register16.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 5 / 5 totaltotal 100% 52 / 52 SCAR 11.0
CC
3
Cov
100%
get
2.0
set
2.0
BEGIN
1.0
CRAP 3.0
« Z80/ALU.pm ↑ Summary Z80/Register8.pm »
1 # $Id: Register16.pm,v 1.6 2008/02/24 20:00:53 drhyde Exp $
2  
3 package CPU::Emulator::Z80::Register16;
4  
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 ▶use base qw(CPU::Emulator::Z80::Register);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 ▶use CPU::Emulator::Z80::ALU;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 15 $VERSION = '1.0';
15  
16 =head1 NAME
17  
18 CPU::Emulator::Z80::Register16 - a 16 bit register for a Z80
19  
20 =head1 DESCRIPTION
21  
22 This class implements a 16-bit register for a Z80.
23  
24 =head1 METHODS
25  
26 =head2 new
27  
28 Returns an object. Takes two or three named parameters:
29  
30 =over
31  
32 =item cpu
33  
34 mandatory, a reference to the CPU this register lives in, mostly so
35 that operations on the register can get at the flags register.
36  
37 =back
38  
39 and either of:
40  
41 =over
42  
43 =item value
44  
45 The value to initialise the register to;
46  
47 =back
48  
49 or
50  
51 =over
52  
53 =item get, set
54  
55 Subroutines to call when getting/setting the register instead of
56 the default get/set methods. The 'get' subroutine will be passed
57 no parameters, the 'set' subroutine will be passed the new value.
58 Consequently, they are expected to be closures if they are to be
59 of any use.
60  
61 =back
62  
63 =cut
64  
65 sub new {
66 17044 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
67 17044 my $self = {@_, bits => 16};
68 17044 $self->{bits} = 16;
69 17044 bless $self, $class;
70 }
71  
72 =head2 get
73  
74 Get the register's current value.
75  
76 =cut
77  
78 sub get {
79 33823 ▶ my $self = shift;
Subroutine get: called CC=2 SCAR=6.9
Pod documented
80 33823 ▶ if(exists($self->{get})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'get'}) { } 7972 25851 33823
81 7972 return $self->{get}->();
82 25851 } else { return $self->{value} & 0xFFFF }
83 }
84  
85 =head2 set
86  
87 Set the register's value to whatever is passed in as a parameter.
88  
89 =cut
90  
91 sub set {
92 21957 ▶ my $self = shift;
Subroutine set: called CC=2 SCAR=6.9
Pod documented
93 21957 ▶ if(exists($self->{set})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'set'}) { } 7838 14119 21957
94 7838 return $self->{set}->(shift);
95 14119 } else { $self->{value} = shift() & 0xFFFF }
96 }
97  
98 =head2 add
99  
100 Add the specified value to the register, frobbing flags
101  
102 =cut
103  
104 sub add {
105 20 ▶ my($self, $op, $adc) = @_;
Subroutine add: called CC=1 SCAR=0.0
Pod documented
106 # $adc tells us if this is really ADC
107 20 $self->set(
108 ALU_add16($self->cpu()->register('F'), $self->get(), $op, $adc)
109 );
110 }
111  
112 =head2 sub
113  
114 Subtract the specified value from the register.
115  
116 =cut
117  
118 sub sub {
119 31 ▶ my($self, $op) = @_;
Subroutine sub: called CC=1 SCAR=0.0
Pod documented
120 31 $self->set(ALU_sub16($self->cpu()->register('F'), $self->get(), $op));
121 }
122  
123 =head2 inc, dec
124  
125 These use the implementation from the parent class
126  
127 =head1 BUGS/WARNINGS/LIMITATIONS
128  
129 None known.
130  
131 =head1 AUTHOR, COPYRIGHT and LICENCE
132  
133 Copyright 2008 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
134  
135 This software is free-as-in-speech software, and may be used,
136 distributed, and modified under the terms of either the GNU
137 General Public Licence version 2 or the Artistic Licence. It's
138 up to you which one you use. The full text of the licences can
139 be found in the files GPL2.txt and ARTISTIC.txt, respectively.
140  
141 =head1 CONSPIRACY
142  
143 This module is also free-as-in-mason software.
144  
145 =cut
146  
147 15 1;
« Z80/ALU.pm ↑ Summary Z80/Register8.pm »