--- M6502/Screen.pm 2007/08/03 08:44:45 106 +++ M6502/Screen.pm 2007/08/04 13:18:39 121 @@ -62,7 +62,6 @@ my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); -my $rect_screen = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 ); my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 ); =head2 p @@ -107,41 +106,6 @@ return ($x,$y); } -=head2 vram - -Push byte to video memory and draw it - - $screen->vram( $offset, $byte ); - -=cut - -my $_vram_counter; - -sub vram { - - return; - - 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; - - foreach ( 0 .. 7 ) { - 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 @@ -180,25 +144,40 @@ $app->sync; } -=head2 render +=head2 render_vram Render one frame of video ram - $self->render( @video_memory ); + $self->render_vram( @video_memory ); =cut -sub render { +my @flip; + +foreach my $i ( 0 .. 255 ) { + my $t = 0; + $i & 0b00000001 and $t = $t | 0b10000000; + $i & 0b00000010 and $t = $t | 0b01000000; + $i & 0b00000100 and $t = $t | 0b00100000; + $i & 0b00001000 and $t = $t | 0b00010000; + $i & 0b00010000 and $t = $t | 0b00001000; + $i & 0b00100000 and $t = $t | 0b00000100; + $i & 0b01000000 and $t = $t | 0b00000010; + $i & 0b10000000 and $t = $t | 0b00000001; + #warn "$i = $t\n"; + $flip[$i] = $t; +} + + +sub render_vram { my $self = shift; return unless $self->booted; - die "this function isn't supported if scale isn't 1" unless $self->scale == 1; - confess "no data?" unless (@_); confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8)); - my $pixels = pack("C*", @_); + my $pixels = pack("C*", map { $flip[$_] } @_); my $vram = SDL::Surface->new( -width => 256, @@ -210,8 +189,19 @@ $vram->set_colors( 0, $black, $white, $red ); $vram->display_format; - my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 ); - $vram->blit( $rect, $app, $rect_screen ); + my $scale = $self->scale; + + my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); + my $rect_screen = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); + + if ( $scale > 1 ) { + use SDL::Tool::Graphic; + # last parametar is anti-alias + my $zoomed = SDL::Tool::Graphic->zoom( $vram, $self->scale, $self->scale, 1 ); + $zoomed->blit( $rect, $app, $rect_screen ); + } else { + $vram->blit( $rect, $app, $rect_screen ); + } $app->sync; } @@ -327,7 +317,7 @@ while ( 1 ) { $self->key_pressed( 1 ); M6502::exec($run_for); - $self->render( @mem[ 0x6000 .. 0x7fff ] ); + $self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); } }