line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPU::Emulator::Z80::Register8; |
2
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
60041
|
use strict; |
|
18
|
|
|
|
|
42
|
|
|
18
|
|
|
|
|
493
|
|
4
|
18
|
|
|
18
|
|
86
|
use warnings; |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
484
|
|
5
|
|
|
|
|
|
|
|
6
|
18
|
|
|
18
|
|
84
|
use vars qw($VERSION); |
|
18
|
|
|
|
|
31
|
|
|
18
|
|
|
|
|
712
|
|
7
|
|
|
|
|
|
|
|
8
|
18
|
|
|
18
|
|
92
|
use base qw(CPU::Emulator::Z80::Register); |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
6924
|
|
9
|
18
|
|
|
18
|
|
115
|
use CPU::Emulator::Z80::ALU; |
|
18
|
|
|
|
|
46
|
|
|
18
|
|
|
|
|
6076
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.01'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
CPU::Emulator::Z80::Register8 - an 8 bit register for a Z80 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
This class implements an 8-bit register for a Z80. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 new |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Returns an object. Takes two or three named parameters: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=over |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=item cpu |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
mandatory, a reference to the CPU this register lives in, mostly so |
32
|
|
|
|
|
|
|
that operations on the register can get at the flags register. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=back |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
and either of: |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item value |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The value to initialise the register to; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=back |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
or |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=over |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=item get, set |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Subroutines to call when getting/setting the register instead of |
53
|
|
|
|
|
|
|
the default get/set methods. The 'get' subroutine will be passed |
54
|
|
|
|
|
|
|
no parameters, the 'set' subroutine will be passed the new value. |
55
|
|
|
|
|
|
|
Consequently, they are expected to be closures if they are to be |
56
|
|
|
|
|
|
|
of any use. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=back |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
63
|
31515
|
|
|
31515
|
1
|
210939
|
my $class = shift; |
64
|
31515
|
|
|
|
|
69697
|
my $self = {@_, bits => 8}; |
65
|
31515
|
|
|
|
|
101447
|
bless $self, $class; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 get |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Get the register's current value. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get { |
75
|
67841
|
|
|
67841
|
1
|
303857
|
my $self = shift; |
76
|
67841
|
100
|
|
|
|
95906
|
if(exists($self->{get})) { |
77
|
653
|
|
|
|
|
1337
|
return $self->{get}->(); |
78
|
67188
|
|
|
|
|
177929
|
} else { return $self->{value} & 0xFF } |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 set |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Set the register's value to whatever is passed in as a parameter. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub set { |
88
|
40029
|
|
|
40029
|
1
|
154261
|
my $self = shift; |
89
|
40029
|
100
|
|
|
|
55425
|
if(exists($self->{set})) { |
90
|
505
|
|
|
|
|
1074
|
return $self->{set}->(shift); |
91
|
39524
|
|
|
|
|
74520
|
} else { $self->{value} = shift() & 0xFF } |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 inc |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Increment the register and set flags. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub inc { |
101
|
15
|
|
|
15
|
1
|
121
|
my $self = shift; |
102
|
15
|
|
|
|
|
69
|
my $flags = $self->cpu()->register('F'); |
103
|
15
|
|
|
|
|
122
|
$self->set(ALU_inc8($flags, $self->get())); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 dec |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Decrement the register and set flags. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub dec { |
113
|
552
|
|
|
552
|
1
|
2491
|
my $self = shift; |
114
|
552
|
|
|
|
|
1187
|
my $flags = $self->cpu()->register('F'); |
115
|
552
|
|
|
|
|
4037
|
$self->set(ALU_dec8($flags, $self->get())); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 add |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Add the specified value to the register. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=cut |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub add { |
125
|
30
|
|
|
30
|
1
|
78
|
my($self, $op) = @_; |
126
|
30
|
|
|
|
|
117
|
$self->set(ALU_add8($self->cpu()->register('F'), $self->get(), $op)); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 sub |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Subtract the specified value from the register. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub sub { |
136
|
67
|
|
|
67
|
1
|
162
|
my($self, $op) = @_; |
137
|
67
|
|
|
|
|
224
|
$self->set(ALU_sub8($self->cpu()->register('F'), $self->get(), $op)); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 BUGS/WARNINGS/LIMITATIONS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
None known. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT and LICENCE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright 2008 David Cantrell EFE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This software is free-as-in-speech software, and may be used, |
149
|
|
|
|
|
|
|
distributed, and modified under the terms of either the GNU |
150
|
|
|
|
|
|
|
General Public Licence version 2 or the Artistic Licence. It's |
151
|
|
|
|
|
|
|
up to you which one you use. The full text of the licences can |
152
|
|
|
|
|
|
|
be found in the files GPL2.txt and ARTISTIC.txt, respectively. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 CONSPIRACY |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This module is also free-as-in-mason software. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |