/[VRac]/M6502/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 /M6502/Screen.pm

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

revision 33 by dpavlin, Mon Jul 30 21:00:36 2007 UTC revision 75 by dpavlin, Wed Aug 1 12:40:20 2007 UTC
# Line 8  use warnings; Line 8  use warnings;
8  use SDL::App;  use SDL::App;
9  use SDL::Rect;  use SDL::Rect;
10  use SDL::Color;  use SDL::Color;
11    use SDL::Constants;
12    
13  use Carp qw/confess/;  use Carp qw/confess/;
14    use Data::Dump qw/dump/;
15    
16  use base qw(Class::Accessor);  use base qw(Class::Accessor Prefs);
17  __PACKAGE__->mk_accessors(qw(debug scale show_mem mem_dump trace app));  __PACKAGE__->mk_accessors(qw(app));
18    
19    =head1 NAME
20    
21    Screen - simulated 256*256 pixels monochrome screen using SDL
22    
23  =head2 open_screen  =head2 open_screen
24    
# Line 25  our $app; Line 31  our $app;
31  sub open_screen {  sub open_screen {
32          my $self = shift;          my $self = shift;
33    
34            $self->prefs;
35    
36          if ( ! $self->scale ) {          if ( ! $self->scale ) {
37                  $self->scale( 1 );                  $self->scale( 1 );
38                  warn "using default unscaled display\n";                  warn "using default unscaled display\n";
# Line 35  sub open_screen { Line 43  sub open_screen {
43                  -height => 256 * $self->scale,                  -height => 256 * $self->scale,
44                  -depth  => 16,                  -depth  => 16,
45          );          );
46          #$app->grab_input( 0 );          #$app->grab_input( SDL_GRAB_QUERY );
47            $app->grab_input( SDL_GRAB_OFF );
48    
49          warn "# created SDL::App\n";          warn "# created SDL::App\n";
50          $self->app( $app );          $self->app( $app );
# Line 98  Push byte to video memory and draw it Line 107  Push byte to video memory and draw it
107    
108  =cut  =cut
109    
110    my $_vram_counter;
111    
112  sub vram {  sub vram {
113          my ( $self, $offset, $byte ) = @_;          my ( $self, $offset, $byte ) = @_;
114          my $x = ( $offset % 32 ) << 3;          my $x = ( $offset % 32 ) << 3;
115          my $y = $offset >> 5;          my $y = $offset >> 5;
116          my $mask = 1;          my $mask = 1;
117            my $scale = $self->scale;
118    
119          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;
120    
121          foreach ( 0 .. 7 ) {          foreach ( 0 .. 7 ) {
122                  p($x + $_, $y, $byte & $mask );                  my $on = $byte & $mask;
123                    if ( $scale == 1 ) {
124                            $app->pixel( $x + $_, $y, $on ? $white : $black );
125                    } else {
126                            $self->p($x + $_, $y, $on );
127                    }
128                  $mask = $mask << 1;                  $mask = $mask << 1;
129          }          }
130    
131            $app->sync if ( $_vram_counter++ % 10 == 0 );
132  }  }
133    
134  =head2 mmap_pixel  =head2 mmap_pixel
# Line 128  sub mmap_pixel { Line 147  sub mmap_pixel {
147          return unless $self->show_mem && $self->app;          return unless $self->show_mem && $self->app;
148    
149          my ( $x, $y ) = $self->mem_xy( $addr );          my ( $x, $y ) = $self->mem_xy( $addr );
150          warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->trace;          warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->debug;
151    
152          my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b );          my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b );
153          $self->app->pixel( $x, $y, $col );          $self->app->pixel( $x, $y, $col );
# Line 150  sub sync { Line 169  sub sync {
169          $app->sync;          $app->sync;
170  }  }
171    
172    =head2 render
173    
174      $self->render( @video_memory );
175    
176    =cut
177    
178    sub render {
179            my $self = shift;
180    
181            die "this function isn't supported if scale isn't 1" unless $self->scale == 1;
182    
183            my $pixels = pack("C*", @_);
184    
185            my $vram = SDL::Surface->new(
186                    -width => 256,
187                    -height => 256,
188                    -depth => 1,    # 1 bit per pixel
189                    -pitch => 32,   # bytes per line
190                    -from => $pixels,
191            );
192            $vram->set_colors( 0, $black, $white, $red );
193            $vram->display_format;
194    
195            my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 );
196            $vram->blit( $rect, $app, $rect );
197    
198            $app->sync;
199    }
200    
201    =head1 SEE ALSO
202    
203    L<Orao> is sample implementation using this module
204    
205    =head1 AUTHOR
206    
207    Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
208    
209    =head1 COPYRIGHT & LICENSE
210    
211    Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
212    
213    This program is free software; you can redistribute it and/or modify it
214    under the same terms as Perl itself.
215    
216    =cut
217  1;  1;

Legend:
Removed from v.33  
changed lines
  Added in v.75

  ViewVC Help
Powered by ViewVC 1.1.26