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