/[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 30 by dpavlin, Mon Jul 30 17:56:13 2007 UTC revision 45 by dpavlin, Tue Jul 31 09:43:50 2007 UTC
# Line 9  use SDL::App; Line 9  use SDL::App;
9  use SDL::Rect;  use SDL::Rect;
10  use SDL::Color;  use SDL::Color;
11    
12    use Carp qw/confess/;
13    
14  use base qw(Class::Accessor);  use base qw(Class::Accessor);
15  __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));
16    
17  =head2 open_screen  =head2 open_screen
18    
# Line 22  our $app; Line 24  our $app;
24    
25  sub open_screen {  sub open_screen {
26          my $self = shift;          my $self = shift;
27    
28            if ( ! $self->scale ) {
29                    $self->scale( 1 );
30                    warn "using default unscaled display\n";
31            }
32    
33          $app = SDL::App->new(          $app = SDL::App->new(
34                  -width  => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ),                  -width  => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ),
35                  -height => 256 * $self->scale,                  -height => 256 * $self->scale,
# Line 30  sub open_screen { Line 38  sub open_screen {
38          #$app->grab_input( 0 );          #$app->grab_input( 0 );
39    
40          warn "# created SDL::App\n";          warn "# created SDL::App\n";
41            $self->app( $app );
42  }  }
43    
44  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
# Line 89  Push byte to video memory and draw it Line 98  Push byte to video memory and draw it
98    
99  =cut  =cut
100    
101    my $_vram_counter;
102    
103  sub vram {  sub vram {
104          my ( $self, $offset, $byte ) = @_;          my ( $self, $offset, $byte ) = @_;
105          my $x = ( $offset % 32 ) << 3;          my $x = ( $offset % 32 ) << 3;
106          my $y = $offset >> 5;          my $y = $offset >> 5;
107          my $mask = 1;          my $mask = 1;
108            my $scale = $self->scale;
109    
110          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;
111    
112          foreach ( 0 .. 7 ) {          foreach ( 0 .. 7 ) {
113                  p($x + $_, $y, $byte & $mask );                  my $on = $byte & $mask;
114                    if ( $scale == 1 ) {
115                            $app->pixel( $x + $_, $y, $on ? $white : $black );
116                    } else {
117                            $self->p($x + $_, $y, $on );
118                    }
119                  $mask = $mask << 1;                  $mask = $mask << 1;
120          }          }
121    
122            $app->sync if ( $_vram_counter++ % 10 == 0 );
123    }
124    
125    =head2 mmap_pixel
126    
127    Draw pixel in memory map
128    
129      $self->mmap_pixel( $addr, $r, $g, $b );
130    
131    =cut
132    
133    # keep accesses to memory
134    my $_mem_stat;
135    
136    sub mmap_pixel {
137            my ( $self, $addr, $r, $g, $b ) = @_;
138            return unless $self->show_mem && $self->app;
139    
140            my ( $x, $y ) = $self->mem_xy( $addr );
141            warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->debug;
142    
143            my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b );
144            $self->app->pixel( $x, $y, $col );
145    
146            $_mem_stat++;
147            if ( $_mem_stat % 1000 == 0 ) {
148                    $self->app->sync;
149            }
150    }
151    
152    
153    =head2 sync
154    
155      $self->sync;
156    
157    =cut
158    
159    sub sync {
160            $app->sync;
161  }  }
162    
163    1;

Legend:
Removed from v.30  
changed lines
  Added in v.45

  ViewVC Help
Powered by ViewVC 1.1.26