Z80/Register8F.pm

filter: Statementstmt 100% 30 / 30 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 97.6% 41 / 42 SCAR 6.9
CC
2
Cov
100%
_set
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« Z80/Register8.pm ↑ Summary Z80/Register.pm »
1 # $Id: Register8F.pm,v 1.6 2008/02/26 21:54:55 drhyde Exp $
2  
3 package CPU::Emulator::Z80::Register8F;
4  
5 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 15 ▶use vars qw($VERSION $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 15 ▶use base qw(CPU::Emulator::Z80::Register8);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 $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 15 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 ▶ my($self, $flag) = @_;
Subroutine _get: called CC=1 SCAR=0.0
58 873 return !!($self->get() & $flag)
59 }
60 sub _set {
61 4936 ▶ my($self, $flag, $value) = @_;
Subroutine _set: called CC=2 SCAR=6.9
62 4936 ▶ $value = 1 if(!defined($value));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 367 4569 4936
63 4936 $self->set(
64 ($self->get() & (0xFF - $flag)) +
65 $flag * (0 + !!$value)
66 );
67 }
68 sub _reset {
69 856 ▶ my($self, $flag) = @_;
Subroutine _reset: called CC=1 SCAR=0.0
70 856 $self->set($self->get() & (0xFF - $flag));
71 }
72  
73 ▶sub DESTROY{}
Subroutine DESTROY: not called CC=1 SCAR=0.0
74 sub AUTOLOAD {
75 6665 ▶ (my $sub = $AUTOLOAD) =~ s/.*:://;
Subroutine AUTOLOAD: called CC=1 SCAR=0.0
76 6665 my($fn, $flag) = ($sub =~ /^(.*)(.)$/);
77 6665 my $self = shift();
78 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 6665 return *{"_$fn"}->($self, $masks{$flag}, @_);
80 }
81  
82 =head1 BUGS/WARNINGS/LIMITATIONS
83  
84 None known.
85  
86 =head1 AUTHOR, COPYRIGHT and LICENCE
87  
88 Copyright 2008 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt>
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 15 1;
« Z80/Register8.pm ↑ Summary Z80/Register.pm »