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 |
|
|
use base qw(Class::Accessor); |
13 |
|
|
__PACKAGE__->mk_accessors(qw(debug scale show_mem run_for mem_dump trace)); |
14 |
|
|
|
15 |
dpavlin |
30 |
=head2 open_screen |
16 |
dpavlin |
29 |
|
17 |
|
|
Open simulated screen |
18 |
|
|
|
19 |
|
|
=cut |
20 |
|
|
|
21 |
|
|
our $app; |
22 |
|
|
|
23 |
dpavlin |
30 |
sub open_screen { |
24 |
dpavlin |
29 |
my $self = shift; |
25 |
|
|
$app = SDL::App->new( |
26 |
|
|
-width => 256 * $self->scale + ( $self->show_mem ? 256 : 0 ), |
27 |
|
|
-height => 256 * $self->scale, |
28 |
|
|
-depth => 16, |
29 |
|
|
); |
30 |
|
|
#$app->grab_input( 0 ); |
31 |
|
|
|
32 |
|
|
warn "# created SDL::App\n"; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
my $white = SDL::Color->new( -r => 0xff, -g => 0xff, -b => 0xff ); |
36 |
|
|
my $black = SDL::Color->new( -r => 0x80, -g => 0x80, -b => 0x80 ); |
37 |
|
|
|
38 |
|
|
my $red = SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 ); |
39 |
|
|
my $green = SDL::Color->new( -r => 0x00, -g => 0xff, -b => 0x00 ); |
40 |
|
|
my $blue = SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xff ); |
41 |
|
|
|
42 |
|
|
=head2 p |
43 |
|
|
|
44 |
|
|
$screen->p( $x, $y, 1 ); |
45 |
|
|
|
46 |
|
|
=cut |
47 |
|
|
|
48 |
|
|
sub p { |
49 |
|
|
my $self = shift; |
50 |
|
|
|
51 |
|
|
my ($x,$y,$w) = (@_); |
52 |
|
|
|
53 |
|
|
warn "p($x,$y,$w)\n" if $self->debug; |
54 |
|
|
|
55 |
|
|
my $scale = $self->scale; |
56 |
|
|
my $rect = SDL::Rect->new( |
57 |
|
|
-height => $scale, |
58 |
|
|
-width => $scale, |
59 |
|
|
-x => $x * $scale, |
60 |
|
|
-y => $y * $scale, |
61 |
|
|
); |
62 |
|
|
|
63 |
|
|
$app->fill( $rect, $w ? $white : $black ); |
64 |
|
|
$app->update( $rect ); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
=head2 mem_xy |
68 |
|
|
|
69 |
|
|
Helper to return x and y coordinates in memory map |
70 |
|
|
|
71 |
|
|
my ( $x,$y ) = $screen->mem_xy( $address ); |
72 |
|
|
|
73 |
|
|
=cut |
74 |
|
|
|
75 |
|
|
sub mem_xy { |
76 |
|
|
my $self = shift; |
77 |
|
|
my $offset = shift; |
78 |
|
|
my $x = $offset & 0xff; |
79 |
|
|
$x += 256 * $self->scale; |
80 |
|
|
my $y = $offset >> 8; |
81 |
|
|
return ($x,$y); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
=head2 vram |
85 |
|
|
|
86 |
|
|
Push byte to video memory and draw it |
87 |
|
|
|
88 |
|
|
$screen->vram( $offset, $byte ); |
89 |
|
|
|
90 |
|
|
=cut |
91 |
|
|
|
92 |
|
|
sub vram { |
93 |
|
|
my ( $self, $offset, $byte ) = @_; |
94 |
|
|
my $x = ( $offset % 32 ) << 3; |
95 |
|
|
my $y = $offset >> 5; |
96 |
|
|
my $mask = 1; |
97 |
|
|
|
98 |
|
|
printf "## vram %04x %02x*%02x %02x\n", $offset, $x, $y, $byte if $self->trace; |
99 |
|
|
|
100 |
|
|
foreach ( 0 .. 7 ) { |
101 |
|
|
p($x + $_, $y, $byte & $mask ); |
102 |
|
|
$mask = $mask << 1; |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
|