CPU::Emulator::6502::Op::LSR - Shift right


Games-NES-Emulator documentation Contained in the Games-NES-Emulator distribution.

Index


Code Index:

NAME

Top

CPU::Emulator::6502::Op::LSR - Shift right

SYNOPSIS

Top

DESCRIPTION

Top

METHODS

Top

lsr_accumulator( )

Shift the accumulator right.

lsr( $addr )

Shift data at $addr right.

AUTHOR

Top

Brian Cassidy <bricas@cpan.org>

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

* CPU::Emulator::6502

Games-NES-Emulator documentation Contained in the Games-NES-Emulator distribution.
package CPU::Emulator::6502::Op::LSR;

use strict;
use warnings;

use constant INSTRUCTIONS => {
    0x4A => {
        cycles => 2,
        code => \&lsr_accumulator,
    },
    0x46 => {
        addressing => 'zero_page',
        cycles => 5,
        code => \&lsr,
    },
    0x56 => {
        addressing => 'zero_page_x',
        cycles => 6,
        code => \&lsr,
    },
    0x4E => {
        addressing => 'absolute',
        cycles => 6,
        code => \&lsr,
    },
    0x5E => {
        addressing => 'absolute_x',
        cycles => 7,
        code => \&lsr,
    },
};

sub lsr_accumulator {
    my $self = shift;
    my $reg = $self->registers;

    $reg->{ status } &= CPU::Emulator::6502::CLEAR_SZC;
    $reg->{ status } |= CPU::Emulator::6502::SET_CARRY if $reg->{ acc } & 1;

    $reg->{ acc } >>= 1;

    $reg->{ status } |= CPU::Emulator::6502::SET_ZERO if $reg->{ acc } == 0;
}

    
sub lsr {
    my $self = shift;
    my $addr = shift;
    my $reg = $self->registers;

    my $temp = $self->memory->[ $addr ];

    $reg->{ status } &= CPU::Emulator::6502::CLEAR_SZC;
    $reg->{ status } |= CPU::Emulator::6502::SET_CARRY if $temp & 1;

    $temp >>= 1;

    $reg->{ status } |= CPU::Emulator::6502::SET_ZERO if $temp == 0;

    $self->RAM_write( $addr => $temp );
}

1;