CPU::Emulator::6502::Addressing - Handle different addressing rules


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

Index


Code Index:

NAME

Top

CPU::Emulator::6502::Addressing - Handle different addressing rules

SYNOPSIS

Top

DESCRIPTION

Top

METHODS

Top

immediate( )

Immediate addressing; immediately following the op.

zero_page( )

Zero Page addressing. Address $00nn.

zero_page_x( )

Zero Page addressing, X indexed. $00nn + X.

zero_page_y( )

Zero Page addressing, Y indexed. $00nn + Y.

indirect( )

Indirect Addressing. Special for JMP.

absolute( )

Absolute addressing. Fetches the next two memory slots and combines them into a 16-bit word.

absolute_x( )

Absolute addressing, X indexed. Fetches the next two memory slots and combines them into a 16-bit word, then adds X.

absolute_y( )

Absolute addressing, Y indexed. Fetches the next two memory slots and combines them into a 16-bit word, then adds Y.

indirect_x( )

Indirect addressing, X indexed.

indirect_y( )

Indirect addressing, Y indexed.

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

use strict;
use warnings;

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

    return $reg->{ pc }++;
}

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

    return $self->memory->[ $reg->{ pc }++ ];
}

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

    return ( $self->memory->[ $reg->{ pc }++ ] + $reg->{ x } ) & 0xff;
}

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

    return ( $self->memory->[ $reg->{ pc }++ ] + $reg->{ y } ) & 0xff;
}

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

    my $lo = $mem->[ $reg->{ pc }++ ];
    my $hi = $mem->[ $reg->{ pc }++ ];
    my $temp = $self->make_word( $lo, $hi );
    my $pcl = $mem->[ $temp ];
    $lo++;
    $temp = $self->make_word( $lo, $hi );
    my $pch = $mem->[ $temp ];

    return $self->make_word( $pcl, $pch );
}

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

    return $self->make_word( $mem->[ $reg->{ pc }++ ], $mem->[ $reg->{ pc }++ ] );
}

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

    return $self->make_word( $mem->[ $reg->{ pc }++ ], $mem->[ $reg->{ pc }++ ] ) + $reg->{ x };

}

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

    return $self->make_word( $mem->[ $reg->{ pc }++ ], $mem->[ $reg->{ pc }++ ] ) + $reg->{ y };
}

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

    my $hi = ( $self->memory->[ $reg->{ pc }++ ] + $reg->{ x } ) & 0xFF;
    return $self->make_word( $self->memory->[ $hi ], $self->memory->[ $hi + 1 ] );
}

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

    my $hi = ( $self->memory->[ $reg->{ pc }++ ] + $reg->{ y } ) & 0xFF;
    return $self->make_word( $self->memory->[ $hi ], $self->memory->[ $hi + 1 ] );
}

1;