line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Register16.pm,v 1.6 2008/02/24 20:00:53 drhyde Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPU::Emulator::Z80::Register16; |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
30757
|
use strict; |
|
14
|
|
|
|
|
64
|
|
|
14
|
|
|
|
|
490
|
|
6
|
14
|
|
|
14
|
|
76
|
use warnings; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
396
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
69
|
use vars qw($VERSION); |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
705
|
|
9
|
|
|
|
|
|
|
|
10
|
14
|
|
|
14
|
|
76
|
use base qw(CPU::Emulator::Z80::Register); |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
1817
|
|
11
|
|
|
|
|
|
|
|
12
|
14
|
|
|
14
|
|
113
|
use CPU::Emulator::Z80::ALU; |
|
14
|
|
|
|
|
32
|
|
|
14
|
|
|
|
|
9349
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$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
|
|
|
17044
|
1
|
161544
|
my $class = shift; |
67
|
17044
|
|
|
|
|
573042
|
my $self = {@_, bits => 16}; |
68
|
17044
|
|
|
|
|
43957
|
$self->{bits} = 16; |
69
|
17044
|
|
|
|
|
185611
|
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
|
|
|
33823
|
1
|
368574
|
my $self = shift; |
80
|
33823
|
100
|
|
|
|
94798
|
if(exists($self->{get})) { |
81
|
7972
|
|
|
|
|
38963
|
return $self->{get}->(); |
82
|
25851
|
|
|
|
|
143647
|
} 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
|
|
|
21957
|
1
|
258414
|
my $self = shift; |
93
|
21957
|
100
|
|
|
|
67287
|
if(exists($self->{set})) { |
94
|
7838
|
|
|
|
|
38553
|
return $self->{set}->(shift); |
95
|
14119
|
|
|
|
|
67575
|
} 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
|
|
|
20
|
1
|
53
|
my($self, $op, $adc) = @_; |
106
|
|
|
|
|
|
|
# $adc tells us if this is really ADC |
107
|
20
|
|
|
|
|
277
|
$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
|
|
|
31
|
1
|
227
|
my($self, $op) = @_; |
120
|
31
|
|
|
|
|
114
|
$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 EFE |
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
|
|
|
|
|
|
|
1; |