CPU::Emulator::6502::Op::ROR - Rotate right through carry


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

Index


Code Index:

NAME

Top

CPU::Emulator::6502::Op::ROR - Rotate right through carry

SYNOPSIS

Top

DESCRIPTION

Top

METHODS

Top

ror_accumulator( $addr )

Rotate left through carry with accumulator.

ror( $addr )

Rotate left through carry with $addr.

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::ROR;

use strict;
use warnings;

use constant INSTRUCTIONS => {
    0x6A => {
        cycles => 2,
        code => \&ror_accumulator,
    },
    0x66 => {
        addressing => 'zero_page',
        cycles => 5,
        code => \&ror,
    },
    0x76 => {
        addressing => 'zero_page_x',
        cycles => 6,
        code => \&ror,
    },
    0x6E => {
        addressing => 'absolute',
        cycles => 6,
        code => \&ror,
    },
    0x7E => {
        addressing => 'absolute_x',
        cycles => 7,
        code => \&ror,
    },
};

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

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

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

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

    $self->set_nz( $reg->{ acc } );
}

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

    my $temp = $self->memory->[ $addr ];
    $temp |= 0x100 if $reg->{ status } & CPU::Emulator::6502::SET_CARRY;

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

    $temp = $temp >> 1;

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

1;