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