line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Register8F.pm,v 1.6 2008/02/26 21:54:55 drhyde Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package CPU::Emulator::Z80::Register8F; |
4
|
|
|
|
|
|
|
|
5
|
14
|
|
|
14
|
|
22739
|
use strict; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
608
|
|
6
|
14
|
|
|
14
|
|
78
|
use warnings; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
488
|
|
7
|
|
|
|
|
|
|
|
8
|
14
|
|
|
14
|
|
68
|
use vars qw($VERSION $AUTOLOAD); |
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
806
|
|
9
|
|
|
|
|
|
|
|
10
|
14
|
|
|
14
|
|
80
|
use base qw(CPU::Emulator::Z80::Register8); |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
7451
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
$VERSION = '1.0'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
CPU::Emulator::Z80::Register8F - the flags register for a Z80 |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This class is a ...::Register8 with additional methods for |
21
|
|
|
|
|
|
|
getting at the individual flag bits |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
It has the same methods as its parent, with the following additions: |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 getX/setX/resetX |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
where X can be any of S Z H P N C 5 or 3, where 5 and 3 are the |
30
|
|
|
|
|
|
|
un-named bits 5 and 3 of the register (0 being the least-significant |
31
|
|
|
|
|
|
|
bit). |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
getX takes no parameters and returns 1 or 0 depending |
34
|
|
|
|
|
|
|
on the flag's status. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
setX if called with no parameters sets the flag true. If called with |
37
|
|
|
|
|
|
|
a parameter it sets the flag true or false depending on the param's |
38
|
|
|
|
|
|
|
value. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
resetX takes no parameters and sets the flag false. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
my %masks = ( |
45
|
|
|
|
|
|
|
S => 0b10000000, # sign (copy of MSB) |
46
|
|
|
|
|
|
|
Z => 0b01000000, # zero |
47
|
|
|
|
|
|
|
5 => 0b00100000, |
48
|
|
|
|
|
|
|
H => 0b00010000, # half-carry (from bit 3 to 4) |
49
|
|
|
|
|
|
|
3 => 0b00001000, |
50
|
|
|
|
|
|
|
P => 0b00000100, # parity (set if even number of bits set) |
51
|
|
|
|
|
|
|
# overflow (2-comp result doesn't fit in reg) |
52
|
|
|
|
|
|
|
N => 0b00000010, # subtract (was the last op a subtraction?) |
53
|
|
|
|
|
|
|
C => 0b00000001 # carry (result doesn't fit in register) |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _get { |
57
|
873
|
|
|
873
|
|
1426
|
my($self, $flag) = @_; |
58
|
873
|
|
|
|
|
2802
|
return !!($self->get() & $flag) |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub _set { |
61
|
4936
|
|
|
4936
|
|
8827
|
my($self, $flag, $value) = @_; |
62
|
4936
|
100
|
|
|
|
15100
|
$value = 1 if(!defined($value)); |
63
|
4936
|
|
|
|
|
18846
|
$self->set( |
64
|
|
|
|
|
|
|
($self->get() & (0xFF - $flag)) + |
65
|
|
|
|
|
|
|
$flag * (0 + !!$value) |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub _reset { |
69
|
856
|
|
|
856
|
|
1763
|
my($self, $flag) = @_; |
70
|
856
|
|
|
|
|
3153
|
$self->set($self->get() & (0xFF - $flag)); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
|
0
|
sub DESTROY{} |
74
|
|
|
|
|
|
|
sub AUTOLOAD { |
75
|
6665
|
|
|
6665
|
|
69310
|
(my $sub = $AUTOLOAD) =~ s/.*:://; |
76
|
6665
|
|
|
|
|
33848
|
my($fn, $flag) = ($sub =~ /^(.*)(.)$/); |
77
|
6665
|
|
|
|
|
14740
|
my $self = shift(); |
78
|
14
|
|
|
14
|
|
92
|
no strict 'refs'; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
1635
|
|
79
|
6665
|
|
|
|
|
21147
|
return *{"_$fn"}->($self, $masks{$flag}, @_); |
|
6665
|
|
|
|
|
33253
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 BUGS/WARNINGS/LIMITATIONS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
None known. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR, COPYRIGHT and LICENCE |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Copyright 2008 David Cantrell EFE |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This software is free-as-in-speech software, and may be used, |
91
|
|
|
|
|
|
|
distributed, and modified under the terms of either the GNU |
92
|
|
|
|
|
|
|
General Public Licence version 2 or the Artistic Licence. It's |
93
|
|
|
|
|
|
|
up to you which one you use. The full text of the licences can |
94
|
|
|
|
|
|
|
be found in the files GPL2.txt and ARTISTIC.txt, respectively. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 CONSPIRACY |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module is also free-as-in-mason software. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |