line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CPU::Emulator::Z80::Register; |
2
|
|
|
|
|
|
|
|
3
|
19
|
|
|
19
|
|
137
|
use vars qw($VERSION); |
|
19
|
|
|
|
|
32
|
|
|
19
|
|
|
|
|
815
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
$VERSION = '1.01'; |
6
|
|
|
|
|
|
|
|
7
|
19
|
|
|
19
|
|
6849
|
use CPU::Emulator::Z80::ALU; |
|
19
|
|
|
|
|
44
|
|
|
19
|
|
|
|
|
3328
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CPU::Emulator::Z80::Register - a register for a Z80 |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This is a base class that defines some useful routines for |
16
|
|
|
|
|
|
|
registers of any size. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
The following methods exist in the base class: |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 getsigned |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Decodes the register 2s-complement-ly and return a signed value. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub getsigned { |
29
|
8
|
|
|
8
|
1
|
13
|
my $self = shift; |
30
|
8
|
|
|
|
|
19
|
my $value = $self->get(); |
31
|
8
|
|
|
|
|
23
|
return ALU_getsigned($value, $self->{bits}); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 cpu |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Return a reference to the CPU this object lives in. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
715
|
|
|
715
|
1
|
1603
|
sub cpu { shift()->{cpu}; } |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 inc |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Increment the register. But note that if incrementing means you |
45
|
|
|
|
|
|
|
need to do anything else, such as set flags, you will need to |
46
|
|
|
|
|
|
|
override this. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub inc { |
51
|
1685
|
|
|
1685
|
1
|
3028
|
my $self = shift(); |
52
|
1685
|
|
|
|
|
3414
|
$self->set($self->get() + 1); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 dec |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Decrement the register, again without bothering with flags and |
58
|
|
|
|
|
|
|
stuff so override if necessary. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub dec { |
63
|
54
|
|
|
54
|
1
|
418
|
my $self = shift; |
64
|
54
|
|
|
|
|
119
|
$self->set($self->get() - 1); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=pod |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
and the following methods need to be defined in all sub-classes: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 get, set |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Must be over-ridden in |
74
|
|
|
|
|
|
|
sub-classes such |
75
|
|
|
|
|
|
|
that setting stores a value, truncated to the right length, and |
76
|
|
|
|
|
|
|
getting retrieves a value, truncated to the right length. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
The set() method must accept -ve values and store them in |
79
|
|
|
|
|
|
|
2s-complement. Its behaviour is undefined if the user is foolish |
80
|
|
|
|
|
|
|
enough to store too large a -ve value. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
The get() method must return the value assuming it to be unsigned. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 FIELDS |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
All subclasses must have the following fields: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 bits |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The number of bits in the register |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 cpu |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
A reference to the CPU this register resides in - this is so that |
95
|
|
|
|
|
|
|
mathemagical operators can get at the flags register. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT and LICENCE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Copyright 2008 David Cantrell EFE |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This software is free-as-in-speech software, and may be used, |
102
|
|
|
|
|
|
|
distributed, and modified under the terms of either the GNU |
103
|
|
|
|
|
|
|
General Public Licence version 2 or the Artistic Licence. It's |
104
|
|
|
|
|
|
|
up to you which one you use. The full text of the licences can |
105
|
|
|
|
|
|
|
be found in the files GPL2.txt and ARTISTIC.txt, respectively. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 CONSPIRACY |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This module is also free-as-in-mason software. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |