CPU::Emulator::6502::Op::JSR - Jump and save the return address


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

Index


Code Index:

NAME

Top

CPU::Emulator::6502::Op::JSR - Jump and save the return address

SYNOPSIS

Top

DESCRIPTION

Top

METHODS

Top

jsr( $addr )

Save return address and jump to $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::JSR;

use strict;
use warnings;

use constant INSTRUCTIONS => {
    0x20 => {
        addressing => 'absolute',
        cycles     => 6,
        code => \&jsr,
    }
};

sub jsr {
    my $self = shift;
    my $addr = shift;
    my $reg = $self->registers;
    my $mem = $self->memory;

    $reg->{ pc }--;
    $self->push_stack( $self->hi_byte( $reg->{ pc } ) );
    $self->push_stack( $self->lo_byte( $reg->{ pc } ) );
    $reg->{ pc } = $addr;
}

1;