/[VRac]/Screen.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 124 by dpavlin, Sat Aug 4 14:13:28 2007 UTC revision 125 by dpavlin, Sat Aug 4 15:09:44 2007 UTC
# Line 14  use Carp qw/confess/; Line 14  use Carp qw/confess/;
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15  use M6502 qw'@mem';  use M6502 qw'@mem';
16    
17    use Exporter 'import';
18    our @EXPORT = qw'$white $black';
19    
20  use base qw(Class::Accessor Prefs);  use base qw(Class::Accessor Prefs);
21  __PACKAGE__->mk_accessors(qw(app event));  __PACKAGE__->mk_accessors(qw(app event));
22    
# Line 55  sub open_screen { Line 58  sub open_screen {
58          warn "# created SDL::App\n";          warn "# created SDL::App\n";
59  }  }
60    
61  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );  our $white      = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
62  my $black       = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 );  our $black      = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 );
63    
64  my $red         = SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 );  my $red         = SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 );
65  my $green       = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 );  my $green       = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 );
# Line 64  my $blue       = SDL::Color->new( -r => 0x00, Line 67  my $blue       = SDL::Color->new( -r => 0x00,
67    
68  my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 );  my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 );
69    
 =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 );  
 }  
   
70  =head2 mem_xy  =head2 mem_xy
71    
72  Helper to return x and y coordinates in memory map  Helper to return x and y coordinates in memory map
# Line 152  Render one frame of video ram Line 130  Render one frame of video ram
130    
131  =cut  =cut
132    
133  my @flip;  sub render_vram {
134            my $self = shift;
135    
136  foreach my $i ( 0 .. 255 ) {          confess "please implement $self::render_vram";
         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;  
137  }  }
138    
139    
140  sub render_vram {  =head2 render_frame
         my $self = shift;  
141    
142          return unless $self->booted;  Render one frame of video ram
143    
144          confess "no data?" unless (@_);    $self->render_frame( $vram_sdl_surface );
         confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8));  
145    
146          my $pixels = pack("C*", map { $flip[$_] } @_);  =cut
147    
148    sub render_frame {
149            my $self = shift;
150    
151            my $vram = shift;
152            confess "need SDL::Surface as argument" unless ref($vram) eq 'SDL::Surface';
153    
         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 );  
154          $vram->display_format;          $vram->display_format;
155    
156          my $scale = $self->scale;          my $scale = $self->scale || confess "no scale?";
157    
158          my $rect                = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale );          my $rect                = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale );
159          my $rect_screen = 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 );
# Line 206  sub render_vram { Line 170  sub render_vram {
170          $app->sync;          $app->sync;
171  }  }
172    
173    
174  =head2 render_mem  =head2 render_mem
175    
176    $self->render_mem( @ram );    $self->render_mem( @ram );
# Line 312  sub loop { Line 277  sub loop {
277          my $self = shift;          my $self = shift;
278          my $event = SDL::Event->new();          my $event = SDL::Event->new();
279    
   
280          MAIN_LOOP:          MAIN_LOOP:
281          while ( 1 ) {          while ( 1 ) {
282                  $self->key_pressed( 1 );                  $self->key_pressed( 1 );

Legend:
Removed from v.124  
changed lines
  Added in v.125

  ViewVC Help
Powered by ViewVC 1.1.26