12 |
|
|
13 |
use Carp qw/confess/; |
use Carp qw/confess/; |
14 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
|
use M6502 qw'@mem'; |
|
15 |
|
|
16 |
use Exporter 'import'; |
use Exporter 'import'; |
17 |
our @EXPORT = qw'$white $black'; |
our @EXPORT = qw'$white $black'; |
45 |
-width => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ), |
-width => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ), |
46 |
-height => 256 * $self->scale, |
-height => 256 * $self->scale, |
47 |
-depth => 16, |
-depth => 16, |
48 |
|
-flags=>SDL_DOUBLEBUF | SDL_HWSURFACE | SDL_HWACCEL, |
49 |
); |
); |
50 |
#$app->grab_input( SDL_GRAB_QUERY ); |
#$app->grab_input( SDL_GRAB_QUERY ); |
51 |
$app->grab_input( SDL_GRAB_OFF ); |
$app->grab_input( SDL_GRAB_OFF ); |
52 |
|
$app->title( ref($self) . ' ' . $self::VERSION ); |
53 |
|
|
54 |
$self->app( $app ); |
$self->app( $app ); |
55 |
|
|
66 |
my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); |
my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); |
67 |
my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); |
my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); |
68 |
|
|
|
my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 ); |
|
|
|
|
69 |
=head2 mem_xy |
=head2 mem_xy |
70 |
|
|
71 |
Helper to return x and y coordinates in memory map |
Helper to return x and y coordinates in memory map |
125 |
|
|
126 |
Render one frame of video ram |
Render one frame of video ram |
127 |
|
|
128 |
$self->render_vram( @video_memory ); |
$self->render_vram; |
129 |
|
|
130 |
=cut |
=cut |
131 |
|
|
154 |
|
|
155 |
my $scale = $self->scale || confess "no scale?"; |
my $scale = $self->scale || confess "no scale?"; |
156 |
|
|
157 |
my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); |
my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); |
158 |
my $rect_screen = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); |
my $rect_screen = SDL::Rect->new( -x => 0, -y => 0, -width => 256 * $scale, -height => 256 * $scale ); |
159 |
|
|
160 |
if ( $scale > 1 ) { |
if ( $scale > 1 ) { |
172 |
|
|
173 |
=head2 render_mem |
=head2 render_mem |
174 |
|
|
175 |
$self->render_mem( @ram ); |
$self->render_mem( @mem ); |
176 |
|
|
177 |
=cut |
=cut |
178 |
|
|
196 |
|
|
197 |
$vram->display_format; |
$vram->display_format; |
198 |
|
|
199 |
my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 ); |
my $rect = SDL::Rect->new( -x => 0, -y => 0, -width => 256, -height => 256 ); |
200 |
|
my $rect_mem = SDL::Rect->new( -x => 256 * $self->scale, -y => 0, -width => 256, -height => 256 ); |
201 |
|
|
202 |
$vram->blit( $rect, $app, $rect_mem ); |
$vram->blit( $rect, $app, $rect_mem ); |
203 |
|
|
204 |
$app->sync; |
$app->sync; |
263 |
undef $pending_key; |
undef $pending_key; |
264 |
} |
} |
265 |
|
|
266 |
warn "key_pressed = $pending_key\n" if $pending_key; |
if ( $pending_key ) { |
267 |
|
warn "key_pressed = $pending_key\n"; |
268 |
|
$self->record_session('key_pressed', $pending_key); |
269 |
|
} |
270 |
|
|
271 |
return $pending_key; |
return $pending_key; |
272 |
} |
} |
273 |
|
|
274 |
=head2 loop |
=head2 loop |
275 |
|
|
276 |
Implement SDL event loop |
Implement CPU run for C<$run_run> cycles inside SDL event loop |
277 |
|
|
278 |
|
$self->loop( sub { |
279 |
|
my $run_for = shift; |
280 |
|
CPU::exec( $run_for ); |
281 |
|
$self->render_vram; |
282 |
|
} ); |
283 |
|
|
284 |
=cut |
=cut |
285 |
|
|
286 |
sub loop { |
sub loop { |
287 |
my $self = shift; |
my $self = shift; |
288 |
|
my $exec = shift; |
289 |
|
|
290 |
|
confess "need coderef as argument" unless ref($exec) eq 'CODE'; |
291 |
my $event = SDL::Event->new(); |
my $event = SDL::Event->new(); |
292 |
|
|
|
MAIN_LOOP: |
|
293 |
while ( 1 ) { |
while ( 1 ) { |
294 |
$self->key_pressed( 1 ); |
$self->key_pressed( 1 ); |
295 |
M6502::exec($run_for); |
$exec->($run_for); |
|
$self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); |
|
296 |
} |
} |
297 |
} |
} |
298 |
|
|