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 |
|
|
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, |
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 ); |
107 |
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; |
108 |
|
|
109 |
foreach ( 0 .. 7 ) { |
foreach ( 0 .. 7 ) { |
110 |
p($x + $_, $y, $byte & $mask ); |
$self->p($x + $_, $y, $byte & $mask ); |
111 |
$mask = $mask << 1; |
$mask = $mask << 1; |
112 |
} |
} |
113 |
} |
} |
114 |
|
|
115 |
|
=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 |
|
return unless $self->show_mem && $self->app; |
129 |
|
|
130 |
|
my ( $x, $y ) = $self->mem_xy( $addr ); |
131 |
|
warn sprintf "## mem %04x %02x %02x %02d*%02d\n", $addr, $r, $g, $x, $y if $self->trace; |
132 |
|
|
133 |
|
my $col = SDL::Color->new( -r => $r, -g => $g, -b => $b ); |
134 |
|
$self->app->pixel( $x, $y, $col ); |
135 |
|
|
136 |
|
$_mem_stat++; |
137 |
|
if ( $_mem_stat % 1000 == 0 ) { |
138 |
|
$self->app->sync; |
139 |
|
} |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
=head2 sync |
144 |
|
|
145 |
|
$self->sync; |
146 |
|
|
147 |
|
=cut |
148 |
|
|
149 |
|
sub sync { |
150 |
|
$app->sync; |
151 |
|
} |
152 |
|
|
153 |
|
1; |