| 1 | # $Id: Register16.pm,v 1.6 2008/02/24 20:00:53 drhyde Exp $ | ||||||||||
| 2 | |||||||||||
| 3 | package CPU::Emulator::Z80::Register16; | ||||||||||
| 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); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 15 | ▶ | use base qw(CPU::Emulator::Z80::Register); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 15 | ▶ | use CPU::Emulator::Z80::ALU; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 15 | $VERSION = '1.0'; | |||||||||
| 15 | |||||||||||
| 16 | =head1 NAME | ||||||||||
| 17 | |||||||||||
| 18 | CPU::Emulator::Z80::Register16 - a 16 bit register for a Z80 | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | This class implements a 16-bit register for a Z80. | ||||||||||
| 23 | |||||||||||
| 24 | =head1 METHODS | ||||||||||
| 25 | |||||||||||
| 26 | =head2 new | ||||||||||
| 27 | |||||||||||
| 28 | Returns an object. Takes two or three named parameters: | ||||||||||
| 29 | |||||||||||
| 30 | =over | ||||||||||
| 31 | |||||||||||
| 32 | =item cpu | ||||||||||
| 33 | |||||||||||
| 34 | mandatory, a reference to the CPU this register lives in, mostly so | ||||||||||
| 35 | that operations on the register can get at the flags register. | ||||||||||
| 36 | |||||||||||
| 37 | =back | ||||||||||
| 38 | |||||||||||
| 39 | and either of: | ||||||||||
| 40 | |||||||||||
| 41 | =over | ||||||||||
| 42 | |||||||||||
| 43 | =item value | ||||||||||
| 44 | |||||||||||
| 45 | The value to initialise the register to; | ||||||||||
| 46 | |||||||||||
| 47 | =back | ||||||||||
| 48 | |||||||||||
| 49 | or | ||||||||||
| 50 | |||||||||||
| 51 | =over | ||||||||||
| 52 | |||||||||||
| 53 | =item get, set | ||||||||||
| 54 | |||||||||||
| 55 | Subroutines to call when getting/setting the register instead of | ||||||||||
| 56 | the default get/set methods. The 'get' subroutine will be passed | ||||||||||
| 57 | no parameters, the 'set' subroutine will be passed the new value. | ||||||||||
| 58 | Consequently, they are expected to be closures if they are to be | ||||||||||
| 59 | of any use. | ||||||||||
| 60 | |||||||||||
| 61 | =back | ||||||||||
| 62 | |||||||||||
| 63 | =cut | ||||||||||
| 64 | |||||||||||
| 65 | sub new { | ||||||||||
| 66 | 17044 | ▶ | my $class = shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 17044 | my $self = {@_, bits => 16}; | |||||||||
| 68 | 17044 | $self->{bits} = 16; | |||||||||
| 69 | 17044 | bless $self, $class; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | =head2 get | ||||||||||
| 73 | |||||||||||
| 74 | Get the register's current value. | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | sub get { | ||||||||||
| 79 | 33823 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 33823 | ▶ | if(exists($self->{get})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 7972 | return $self->{get}->(); | |||||||||
| 82 | 25851 | } else { return $self->{value} & 0xFFFF } | |||||||||
| 83 | } | ||||||||||
| 84 | |||||||||||
| 85 | =head2 set | ||||||||||
| 86 | |||||||||||
| 87 | Set the register's value to whatever is passed in as a parameter. | ||||||||||
| 88 | |||||||||||
| 89 | =cut | ||||||||||
| 90 | |||||||||||
| 91 | sub set { | ||||||||||
| 92 | 21957 | ▶ | my $self = shift; | ||||||||
|
Subroutine
set: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 21957 | ▶ | if(exists($self->{set})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 7838 | return $self->{set}->(shift); | |||||||||
| 95 | 14119 | } else { $self->{value} = shift() & 0xFFFF } | |||||||||
| 96 | } | ||||||||||
| 97 | |||||||||||
| 98 | =head2 add | ||||||||||
| 99 | |||||||||||
| 100 | Add the specified value to the register, frobbing flags | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||
| 103 | |||||||||||
| 104 | sub add { | ||||||||||
| 105 | 20 | ▶ | my($self, $op, $adc) = @_; | ||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 106 | # $adc tells us if this is really ADC | ||||||||||
| 107 | 20 | $self->set( | |||||||||
| 108 | ALU_add16($self->cpu()->register('F'), $self->get(), $op, $adc) | ||||||||||
| 109 | ); | ||||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | =head2 sub | ||||||||||
| 113 | |||||||||||
| 114 | Subtract the specified value from the register. | ||||||||||
| 115 | |||||||||||
| 116 | =cut | ||||||||||
| 117 | |||||||||||
| 118 | sub sub { | ||||||||||
| 119 | 31 | ▶ | my($self, $op) = @_; | ||||||||
|
Subroutine
sub: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 120 | 31 | $self->set(ALU_sub16($self->cpu()->register('F'), $self->get(), $op)); | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | =head2 inc, dec | ||||||||||
| 124 | |||||||||||
| 125 | These use the implementation from the parent class | ||||||||||
| 126 | |||||||||||
| 127 | =head1 BUGS/WARNINGS/LIMITATIONS | ||||||||||
| 128 | |||||||||||
| 129 | None known. | ||||||||||
| 130 | |||||||||||
| 131 | =head1 AUTHOR, COPYRIGHT and LICENCE | ||||||||||
| 132 | |||||||||||
| 133 | Copyright 2008 David Cantrell E<lt>F<david@cantrell.org.uk>E<gt> | ||||||||||
| 134 | |||||||||||
| 135 | This software is free-as-in-speech software, and may be used, | ||||||||||
| 136 | distributed, and modified under the terms of either the GNU | ||||||||||
| 137 | General Public Licence version 2 or the Artistic Licence. It's | ||||||||||
| 138 | up to you which one you use. The full text of the licences can | ||||||||||
| 139 | be found in the files GPL2.txt and ARTISTIC.txt, respectively. | ||||||||||
| 140 | |||||||||||
| 141 | =head1 CONSPIRACY | ||||||||||
| 142 | |||||||||||
| 143 | This module is also free-as-in-mason software. | ||||||||||
| 144 | |||||||||||
| 145 | =cut | ||||||||||
| 146 | |||||||||||
| 147 | 15 | 1; | |||||||||