--- Screen.pm 2007/08/04 14:13:28 124 +++ Screen.pm 2007/08/04 15:09:44 125 @@ -14,6 +14,9 @@ use Data::Dump qw/dump/; use M6502 qw'@mem'; +use Exporter 'import'; +our @EXPORT = qw'$white $black'; + use base qw(Class::Accessor Prefs); __PACKAGE__->mk_accessors(qw(app event)); @@ -55,8 +58,8 @@ warn "# created SDL::App\n"; } -my $white = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff ); -my $black = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 ); +our $white = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff ); +our $black = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 ); my $red = SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 ); my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); @@ -64,31 +67,6 @@ my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 ); -=head2 p - - $screen->p( $x, $y, 1 ); - -=cut - -sub p { - my $self = shift; - - my ($x,$y,$w) = (@_); - - warn "p($x,$y,$w)\n" if $self->debug; - - my $scale = $self->scale; - my $rect = SDL::Rect->new( - -height => $scale, - -width => $scale, - -x => $x * $scale, - -y => $y * $scale, - ); - - $app->fill( $rect, $w ? $white : $black ); - $app->update( $rect ); -} - =head2 mem_xy Helper to return x and y coordinates in memory map @@ -152,44 +130,30 @@ =cut -my @flip; +sub render_vram { + my $self = shift; -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; + confess "please implement $self::render_vram"; } -sub render_vram { - my $self = shift; +=head2 render_frame - return unless $self->booted; +Render one frame of video ram - confess "no data?" unless (@_); - confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8)); + $self->render_frame( $vram_sdl_surface ); - my $pixels = pack("C*", map { $flip[$_] } @_); +=cut + +sub render_frame { + my $self = shift; + + my $vram = shift; + confess "need SDL::Surface as argument" unless ref($vram) eq 'SDL::Surface'; - my $vram = SDL::Surface->new( - -width => 256, - -height => 256, - -depth => 1, # 1 bit per pixel - -pitch => 32, # bytes per line - -from => $pixels, - ); - $vram->set_colors( 0, $black, $white, $red ); $vram->display_format; - my $scale = $self->scale; + my $scale = $self->scale || confess "no 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 ); @@ -206,6 +170,7 @@ $app->sync; } + =head2 render_mem $self->render_mem( @ram ); @@ -312,7 +277,6 @@ my $self = shift; my $event = SDL::Event->new(); - MAIN_LOOP: while ( 1 ) { $self->key_pressed( 1 );