/[VRac]/Screen.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /Screen.pm

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26