107 |
return ($x,$y); |
return ($x,$y); |
108 |
} |
} |
109 |
|
|
|
=head2 vram |
|
|
|
|
|
Push byte to video memory and draw it |
|
|
|
|
|
$screen->vram( $offset, $byte ); |
|
|
|
|
|
=cut |
|
|
|
|
|
my $_vram_counter; |
|
|
|
|
|
sub vram { |
|
|
|
|
|
return; |
|
|
|
|
|
my ( $self, $offset, $byte ) = @_; |
|
|
my $x = ( $offset % 32 ) << 3; |
|
|
my $y = $offset >> 5; |
|
|
my $mask = 1; |
|
|
my $scale = $self->scale; |
|
|
|
|
|
printf "## vram %04x %02x*%02x %02x\n", $offset, $x, $y, $byte if $self->trace; |
|
|
|
|
|
foreach ( 0 .. 7 ) { |
|
|
my $on = $byte & $mask; |
|
|
if ( $scale == 1 ) { |
|
|
$app->pixel( $x + $_, $y, $on ? $white : $black ); |
|
|
} else { |
|
|
$self->p($x + $_, $y, $on ); |
|
|
} |
|
|
$mask = $mask << 1; |
|
|
} |
|
|
|
|
|
$app->sync if ( $_vram_counter++ % 10 == 0 ); |
|
|
} |
|
|
|
|
110 |
=head2 mmap_pixel |
=head2 mmap_pixel |
111 |
|
|
112 |
Draw pixel in memory map |
Draw pixel in memory map |
145 |
$app->sync; |
$app->sync; |
146 |
} |
} |
147 |
|
|
148 |
=head2 render |
=head2 render_vram |
149 |
|
|
150 |
Render one frame of video ram |
Render one frame of video ram |
151 |
|
|
152 |
$self->render( @video_memory ); |
$self->render_vram( @video_memory ); |
153 |
|
|
154 |
=cut |
=cut |
155 |
|
|
156 |
sub render { |
my @flip; |
157 |
|
|
158 |
|
foreach my $i ( 0 .. 255 ) { |
159 |
|
my $t = 0; |
160 |
|
$i & 0b00000001 and $t = $t | 0b10000000; |
161 |
|
$i & 0b00000010 and $t = $t | 0b01000000; |
162 |
|
$i & 0b00000100 and $t = $t | 0b00100000; |
163 |
|
$i & 0b00001000 and $t = $t | 0b00010000; |
164 |
|
$i & 0b00010000 and $t = $t | 0b00001000; |
165 |
|
$i & 0b00100000 and $t = $t | 0b00000100; |
166 |
|
$i & 0b01000000 and $t = $t | 0b00000010; |
167 |
|
$i & 0b10000000 and $t = $t | 0b00000001; |
168 |
|
warn "$i = $t\n"; |
169 |
|
$flip[$i] = $t; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
sub render_vram { |
174 |
my $self = shift; |
my $self = shift; |
175 |
|
|
176 |
return unless $self->booted; |
return unless $self->booted; |
180 |
confess "no data?" unless (@_); |
confess "no data?" unless (@_); |
181 |
confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8)); |
confess "screen size not 256*256/8 but ",($#_+1) unless (($#_+1) == (256*256/8)); |
182 |
|
|
183 |
my $pixels = pack("C*", @_); |
|
184 |
|
my $pixels = pack("C*", map { $flip[$_] } @_); |
185 |
|
|
186 |
my $vram = SDL::Surface->new( |
my $vram = SDL::Surface->new( |
187 |
-width => 256, |
-width => 256, |
310 |
while ( 1 ) { |
while ( 1 ) { |
311 |
$self->key_pressed( 1 ); |
$self->key_pressed( 1 ); |
312 |
M6502::exec($run_for); |
M6502::exec($run_for); |
313 |
$self->render( @mem[ 0x6000 .. 0x7fff ] ); |
$self->render_vram( @mem[ 0x6000 .. 0x7fff ] ); |
314 |
} |
} |
315 |
} |
} |
316 |
|
|