| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::NES::ROM::Format::UNIF; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
28723
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Games::NES::ROM'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has '+id' => ( default => "UNIF" ); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'revision' => ( is => 'rw', isa => 'Int', default => 7 ); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'comments' => ( is => 'rw' ); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'tvci' => ( is => 'rw' ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'controller' => ( is => 'rw' ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'has_vror' => ( is => 'rw', isa => 'Bool', default => 0 ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub BUILD { |
|
20
|
|
|
|
|
|
|
my $self = shift; |
|
21
|
|
|
|
|
|
|
my $fh = $self->filehandle; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $id; |
|
24
|
|
|
|
|
|
|
$fh->read( $id, 4 ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
die 'Not a UNIF rom' if $id ne $self->id; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $rev; |
|
29
|
|
|
|
|
|
|
$fh->read( $rev, 4 ); |
|
30
|
|
|
|
|
|
|
$self->revision( unpack( 'V', $rev ) ); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$fh->seek( 24, 1 ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $chunk_header; |
|
35
|
|
|
|
|
|
|
while( $fh->read( $chunk_header, 8 ) ) { |
|
36
|
|
|
|
|
|
|
my( $cid, $length ) = unpack( 'A4 V', $chunk_header ); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $chunk; |
|
39
|
|
|
|
|
|
|
$fh->read( $chunk, $length ); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @args; |
|
42
|
|
|
|
|
|
|
if( $cid =~ m{(CHR|PRG|CCK|PCK)(.)} ) { |
|
43
|
|
|
|
|
|
|
$cid = $1; |
|
44
|
|
|
|
|
|
|
push @args, hex($2); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $name = "_parse_${cid}_chunk"; |
|
48
|
|
|
|
|
|
|
if( my $sub = $self->can( $name ) ) { |
|
49
|
|
|
|
|
|
|
$sub->( $self, $chunk, @args ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$self->clear_filehandle; |
|
54
|
|
|
|
|
|
|
return $self; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _parse_NAME_chunk { |
|
58
|
|
|
|
|
|
|
my( $self, $title ) = @_; |
|
59
|
|
|
|
|
|
|
$self->title( unpack( 'A*', $title ) ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub _parse_PRG_chunk { |
|
63
|
|
|
|
|
|
|
my( $self, $prg, $id ) = @_; |
|
64
|
|
|
|
|
|
|
$self->prg_banks->[ $id ] = $prg; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _parse_CHR_chunk { |
|
68
|
|
|
|
|
|
|
my( $self, $chr, $id ) = @_; |
|
69
|
|
|
|
|
|
|
$self->chr_banks->[ $id ] = $chr; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _parse_READ_chunk { |
|
73
|
|
|
|
|
|
|
my( $self, $comments ) = @_; |
|
74
|
|
|
|
|
|
|
$self->comments( unpack( 'A*', $comments ) ); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _parse_BATR_chunk { |
|
78
|
|
|
|
|
|
|
shift->has_sram( 1 ); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _parse_VROR_chunk { |
|
82
|
|
|
|
|
|
|
shift->has_vror( 1 ); |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _parse_MIRR_chunk { |
|
86
|
|
|
|
|
|
|
my( $self, $mirroring ) = @_; |
|
87
|
|
|
|
|
|
|
$self->mirroring( unpack( 'C', $mirroring ) ); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _parse_TVCI_chunk { |
|
91
|
|
|
|
|
|
|
my( $self, $tvci ) = @_; |
|
92
|
|
|
|
|
|
|
$self->tvci( unpack( 'C', $tvci ) ); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _parse_CTRL_chunk { |
|
96
|
|
|
|
|
|
|
my( $self, $controller ) = @_; |
|
97
|
|
|
|
|
|
|
$self->controller( unpack( 'C', $controller ) ); |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _parse_MAPR_chunk { |
|
101
|
|
|
|
|
|
|
my( $self, $mapper ) = @_; |
|
102
|
|
|
|
|
|
|
$self->mapper( unpack( 'A*', $mapper ) ); |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 NAME |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Games::NES::ROM::Format::UNIF - Loads data from a ROM in UNIF format |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module loads the details of an NES rom in UNIF format. A UNIF file is |
|
118
|
|
|
|
|
|
|
layed out as follows: |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
+----------+ |
|
121
|
|
|
|
|
|
|
| "UNIF" | 4 Bytes |
|
122
|
|
|
|
|
|
|
+----------+ |
|
123
|
|
|
|
|
|
|
| Revision | 32-bit Word |
|
124
|
|
|
|
|
|
|
+----------+ |
|
125
|
|
|
|
|
|
|
| Filler | 24 Bytes |
|
126
|
|
|
|
|
|
|
+----------+ |
|
127
|
|
|
|
|
|
|
| Chunk ID | 4 Bytes |
|
128
|
|
|
|
|
|
|
+----------+ |
|
129
|
|
|
|
|
|
|
| Length | 32-bit Word |
|
130
|
|
|
|
|
|
|
+----------+ |
|
131
|
|
|
|
|
|
|
| Data | |
|
132
|
|
|
|
|
|
|
+----------+ |
|
133
|
|
|
|
|
|
|
etc... |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 METHODS |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head2 BUILD( ) |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
A L<Moose> method which loads the ROM data from a file. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Along with the L<base attributes|Games::NES::ROM/BASE ATTRIBUTES>, the following UNIF specific attributes are |
|
144
|
|
|
|
|
|
|
available: |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=over 4 |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * id - UNIF identifier: "UNIF" |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * revision - The revision of the UNIF spec for this file |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * comments - A set of text comments |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * tvci - Television standards compatability information |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * controller - The controllers used by the cartridge |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * has_vror - The ROM has a VRAM override |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=back |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * Games::NES::ROM |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * http://www.viste-family.net/mateusz/nes/html/tech/unif_cur.txt |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Brian Cassidy E<lt>bricas@cpan.orgE<gt> |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Copyright 2007-2013 by Brian Cassidy |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
181
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |