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 ); |
65 |
my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); |
my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); |
66 |
my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); |
my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); |
67 |
|
|
|
my $rect_mem = SDL::Rect->new( -x => 256, -y => 0, -width => 256, -height => 256 ); |
|
|
|
|
68 |
=head2 mem_xy |
=head2 mem_xy |
69 |
|
|
70 |
Helper to return x and y coordinates in memory map |
Helper to return x and y coordinates in memory map |
124 |
|
|
125 |
Render one frame of video ram |
Render one frame of video ram |
126 |
|
|
127 |
$self->render_vram( @video_memory ); |
$self->render_vram; |
128 |
|
|
129 |
=cut |
=cut |
130 |
|
|
153 |
|
|
154 |
my $scale = $self->scale || confess "no scale?"; |
my $scale = $self->scale || confess "no scale?"; |
155 |
|
|
156 |
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 ); |
157 |
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 ); |
158 |
|
|
159 |
if ( $scale > 1 ) { |
if ( $scale > 1 ) { |
171 |
|
|
172 |
=head2 render_mem |
=head2 render_mem |
173 |
|
|
174 |
$self->render_mem( @ram ); |
$self->render_mem( @mem ); |
175 |
|
|
176 |
=cut |
=cut |
177 |
|
|
195 |
|
|
196 |
$vram->display_format; |
$vram->display_format; |
197 |
|
|
198 |
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 ); |
199 |
|
my $rect_mem = SDL::Rect->new( -x => 256 * $self->scale, -y => 0, -width => 256, -height => 256 ); |
200 |
|
|
201 |
$vram->blit( $rect, $app, $rect_mem ); |
$vram->blit( $rect, $app, $rect_mem ); |
202 |
|
|
203 |
$app->sync; |
$app->sync; |
269 |
|
|
270 |
=head2 loop |
=head2 loop |
271 |
|
|
272 |
Implement SDL event loop |
Implement CPU run for C<$run_run> cycles inside SDL event loop |
273 |
|
|
274 |
|
$self->loop( sub { |
275 |
|
my $run_for = shift; |
276 |
|
CPU::exec( $run_for ); |
277 |
|
$self->render_vram; |
278 |
|
} ); |
279 |
|
|
280 |
=cut |
=cut |
281 |
|
|
282 |
sub loop { |
sub loop { |
283 |
my $self = shift; |
my $self = shift; |
284 |
|
my $exec = shift; |
285 |
|
|
286 |
|
confess "need coderef as argument" unless ref($exec) eq 'CODE'; |
287 |
my $event = SDL::Event->new(); |
my $event = SDL::Event->new(); |
288 |
|
|
|
MAIN_LOOP: |
|
289 |
while ( 1 ) { |
while ( 1 ) { |
290 |
$self->key_pressed( 1 ); |
$self->key_pressed( 1 ); |
291 |
M6502::exec($run_for); |
$exec->($run_for); |
|
$self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); |
|
292 |
} |
} |
293 |
} |
} |
294 |
|
|