/[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 76 by dpavlin, Wed Aug 1 12:57:15 2007 UTC revision 106 by dpavlin, Fri Aug 3 08:44:45 2007 UTC
# Line 12  use SDL::Constants; Line 12  use SDL::Constants;
12    
13  use Carp qw/confess/;  use Carp qw/confess/;
14  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
15    use M6502 qw'@mem';
16    
17  use base qw(Class::Accessor Prefs);  use base qw(Class::Accessor Prefs);
18  __PACKAGE__->mk_accessors(qw(app));  __PACKAGE__->mk_accessors(qw(app event));
19    
20  =head1 NAME  =head1 NAME
21    
# Line 46  sub open_screen { Line 47  sub open_screen {
47          #$app->grab_input( SDL_GRAB_QUERY );          #$app->grab_input( SDL_GRAB_QUERY );
48          $app->grab_input( SDL_GRAB_OFF );          $app->grab_input( SDL_GRAB_OFF );
49    
         warn "# created SDL::App\n";  
50          $self->app( $app );          $self->app( $app );
51    
52            my $event = SDL::Event->new();
53            $self->event( $event );
54    
55            warn "# created SDL::App\n";
56  }  }
57    
58  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );  my $white       = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
# Line 113  Push byte to video memory and draw it Line 118  Push byte to video memory and draw it
118  my $_vram_counter;  my $_vram_counter;
119    
120  sub vram {  sub vram {
121    
122            return;
123    
124          my ( $self, $offset, $byte ) = @_;          my ( $self, $offset, $byte ) = @_;
125          my $x = ( $offset % 32 ) << 3;          my $x = ( $offset % 32 ) << 3;
126          my $y = $offset >> 5;          my $y = $offset >> 5;
# Line 183  Render one frame of video ram Line 191  Render one frame of video ram
191  sub render {  sub render {
192          my $self = shift;          my $self = shift;
193    
194            return unless $self->booted;
195    
196          die "this function isn't supported if scale isn't 1" unless $self->scale == 1;          die "this function isn't supported if scale isn't 1" unless $self->scale == 1;
197    
198            confess "no data?" unless (@_);
199            confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8));
200    
201          my $pixels = pack("C*", @_);          my $pixels = pack("C*", @_);
202    
203          my $vram = SDL::Surface->new(          my $vram = SDL::Surface->new(
# Line 235  sub render_mem { Line 248  sub render_mem {
248          $app->sync;          $app->sync;
249  }  }
250    
251    =head2 key_pressed
252    
253    Check SDL event loop if there are any pending keys
254    
255      my $key = $self->key_pressed;
256    
257      if ( $self->key_pressed( 1 ) ) {
258            # just to check other events, don't process
259            # key
260      }
261    
262    =cut
263    
264    my $pending_key;
265    my $run_for = 2000;
266    
267    my $key_down;
268    
269    sub key_down {
270            my $self = shift;
271            my $key = shift;
272            warn "key_down($key) = ",$key_down->{$key}, "\n" if $self->debug;
273            return $key_down->{$key};
274    }
275    
276    sub key_pressed {
277            my $self = shift;
278    
279            # don't take key, just pull event
280            my $just_checking = shift || 0;
281    
282            my $event = $self->event || confess "no event?";
283    
284            $event->poll || return $pending_key;
285    
286            my $type = $event->type();
287    
288            exit if ($type == SDL_QUIT);
289    
290            my $k = $pending_key;
291    
292            if ($type == SDL_KEYDOWN) {
293                    $k = $event->key_name();
294                    $key_down->{$k}++;
295                    if ( $k eq 'escape' ) {
296                            $run_for = $self->cli;
297                            warn "will check event loop every $run_for cycles\n";
298                            $pending_key = '~';
299                    } else {
300                            warn "SDL_KEYDOWN ($type) = '$k'", $just_checking ? ' fake' : '', "\n";
301                            $pending_key = $k;
302                    }
303            } elsif ( $type == SDL_KEYUP ) {
304                    my $up = $event->key_name();
305                    $key_down->{$up} = 0;
306                    warn "SDL_KEYUP ($type) = '$up'", $just_checking ? ' fake' : '', "\n";
307                    undef $pending_key;
308            }
309    
310            warn "key_pressed = $pending_key\n" if $pending_key;
311    
312            return $pending_key;
313    }
314    
315    =head2 loop
316    
317    Implement SDL event loop
318    
319    =cut
320    
321    sub loop {
322            my $self = shift;
323            my $event = SDL::Event->new();
324    
325    
326            MAIN_LOOP:
327            while ( 1 ) {
328                    $self->key_pressed( 1 );
329                    M6502::exec($run_for);
330                    $self->render( @mem[ 0x6000 .. 0x7fff ] );
331            }
332    }
333    
334  =head1 SEE ALSO  =head1 SEE ALSO
335    
336  L<Orao> is sample implementation using this module  L<Orao> is sample implementation using this module

Legend:
Removed from v.76  
changed lines
  Added in v.106

  ViewVC Help
Powered by ViewVC 1.1.26