--- M6502/Screen.pm 2007/07/30 17:56:13 30 +++ M6502/Screen.pm 2007/07/30 22:27:47 37 @@ -9,8 +9,10 @@ use SDL::Rect; use SDL::Color; +use Carp qw/confess/; + use base qw(Class::Accessor); -__PACKAGE__->mk_accessors(qw(debug scale show_mem run_for mem_dump trace)); +__PACKAGE__->mk_accessors(qw(debug scale show_mem mem_dump trace app)); =head2 open_screen @@ -22,6 +24,12 @@ sub open_screen { my $self = shift; + + if ( ! $self->scale ) { + $self->scale( 1 ); + warn "using default unscaled display\n"; + } + $app = SDL::App->new( -width => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ), -height => 256 * $self->scale, @@ -30,6 +38,7 @@ #$app->grab_input( 0 ); warn "# created SDL::App\n"; + $self->app( $app ); } my $white = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff ); @@ -89,17 +98,66 @@ =cut +my $_vram_counter; + sub vram { my ( $self, $offset, $byte ) = @_; my $x = ( $offset % 32 ) << 3; my $y = $offset >> 5; my $mask = 1; + my $scale = $self->scale; - printf "## vram %04x %02x*%02x %02x\n", $offset, $x, $y, $byte if $self->trace; +# printf "## vram %04x %02x*%02x %02x\n", $offset, $x, $y, $byte if $self->trace; foreach ( 0 .. 7 ) { - p($x + $_, $y, $byte & $mask ); + my $on = $byte & $mask; + if ( $scale == 1 ) { + $app->pixel( $x + $_, $y, $on ? $white : $black ); + } else { + $self->p($x + $_, $y, $on ); + } $mask = $mask << 1; } + + $app->sync if ( $_vram_counter++ % 10 == 0 ); +} + +=head2 mmap_pixel + +Draw pixel in memory map + + $self->mmap_pixel( $addr, $r, $g, $b ); + +=cut + +# keep accesses to memory +my $_mem_stat; + +sub mmap_pixel { + my ( $self, $addr, $r, $g, $b ) = @_; + return unless $self->show_mem && $self->app; + + my ( $x, $y ) = $self->mem_xy( $addr ); + warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->trace; + + my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b ); + $self->app->pixel( $x, $y, $col ); + + $_mem_stat++; + if ( $_mem_stat % 1000 == 0 ) { + $self->app->sync; + } +} + + +=head2 sync + + $self->sync; + +=cut + +sub sync { + $app->sync; } +1;