/[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

Annotation of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 36 - (hide annotations)
Mon Jul 30 22:06:13 2007 UTC (16 years, 8 months ago) by dpavlin
Original Path: M6502/Screen.pm
File size: 2651 byte(s)
more tweaks
1 dpavlin 29 package Screen;
2    
3     # Dobrica Pavlinusic, <dpavlin@rot13.org> 07/30/07 17:58:55 CEST
4    
5     use strict;
6     use warnings;
7    
8     use SDL::App;
9     use SDL::Rect;
10     use SDL::Color;
11    
12 dpavlin 33 use Carp qw/confess/;
13    
14 dpavlin 29 use base qw(Class::Accessor);
15 dpavlin 33 __PACKAGE__->mk_accessors(qw(debug scale show_mem mem_dump trace app));
16 dpavlin 29
17 dpavlin 30 =head2 open_screen
18 dpavlin 29
19     Open simulated screen
20    
21     =cut
22    
23     our $app;
24    
25 dpavlin 30 sub open_screen {
26 dpavlin 29 my $self = shift;
27 dpavlin 31
28     if ( ! $self->scale ) {
29     $self->scale( 1 );
30     warn "using default unscaled display\n";
31     }
32    
33 dpavlin 29 $app = SDL::App->new(
34     -width => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ),
35     -height => 256 * $self->scale,
36     -depth => 16,
37     );
38     #$app->grab_input( 0 );
39    
40     warn "# created SDL::App\n";
41 dpavlin 33 $self->app( $app );
42 dpavlin 29 }
43    
44     my $white = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff );
45     my $black = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 );
46    
47     my $red = SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 );
48     my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 );
49     my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff );
50    
51     =head2 p
52    
53     $screen->p( $x, $y, 1 );
54    
55     =cut
56    
57     sub p {
58     my $self = shift;
59    
60     my ($x,$y,$w) = (@_);
61    
62     warn "p($x,$y,$w)\n" if $self->debug;
63    
64     my $scale = $self->scale;
65     my $rect = SDL::Rect->new(
66     -height => $scale,
67     -width => $scale,
68     -x => $x * $scale,
69     -y => $y * $scale,
70     );
71    
72     $app->fill( $rect, $w ? $white : $black );
73     $app->update( $rect );
74     }
75    
76     =head2 mem_xy
77    
78     Helper to return x and y coordinates in memory map
79    
80     my ( $x,$y ) = $screen->mem_xy( $address );
81    
82     =cut
83    
84     sub mem_xy {
85     my $self = shift;
86     my $offset = shift;
87     my $x = $offset & 0xff;
88     $x += 256 * $self->scale;
89     my $y = $offset >> 8;
90     return ($x,$y);
91     }
92    
93     =head2 vram
94    
95     Push byte to video memory and draw it
96    
97     $screen->vram( $offset, $byte );
98    
99     =cut
100    
101     sub vram {
102     my ( $self, $offset, $byte ) = @_;
103     my $x = ( $offset % 32 ) << 3;
104     my $y = $offset >> 5;
105     my $mask = 1;
106    
107     printf "## vram %04x %02x*%02x %02x\n", $offset, $x, $y, $byte if $self->trace;
108    
109     foreach ( 0 .. 7 ) {
110 dpavlin 36 $self->p($x + $_, $y, $byte & $mask );
111 dpavlin 29 $mask = $mask << 1;
112     }
113     }
114    
115 dpavlin 32 =head2 mmap_pixel
116    
117     Draw pixel in memory map
118    
119     $self->mmap_pixel( $addr, $r, $g, $b );
120    
121     =cut
122    
123     # keep accesses to memory
124     my $_mem_stat;
125    
126     sub mmap_pixel {
127     my ( $self, $addr, $r, $g, $b ) = @_;
128 dpavlin 33 return unless $self->show_mem && $self->app;
129 dpavlin 32
130 dpavlin 33 my ( $x, $y ) = $self->mem_xy( $addr );
131 dpavlin 32 warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->trace;
132    
133 dpavlin 33 my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b );
134     $self->app->pixel( $x, $y, $col );
135 dpavlin 32
136     $_mem_stat++;
137     if ( $_mem_stat % 1000 == 0 ) {
138 dpavlin 33 $self->app->sync;
139 dpavlin 32 }
140     }
141    
142 dpavlin 33
143     =head2 sync
144    
145     $self->sync;
146    
147     =cut
148    
149     sub sync {
150     $app->sync;
151     }
152    
153 dpavlin 32 1;

  ViewVC Help
Powered by ViewVC 1.1.26