| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Games::NES::ROM::Format::INES; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
43207
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
extends 'Games::NES::ROM'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has '+id' => ( default => "NES\x1a" ); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'trainer' => ( is => 'rw' ); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub BUILD { |
|
12
|
|
|
|
|
|
|
my $self = shift; |
|
13
|
|
|
|
|
|
|
my $fh = $self->filehandle; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $id; |
|
16
|
|
|
|
|
|
|
$fh->read( $id, 4 ); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
die 'Not an iNES rom' if $id ne $self->id; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $header; |
|
21
|
|
|
|
|
|
|
$fh->read( $header, 12 ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my @header_vals = unpack( 'C*', $header ); |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$self->mirroring( $header_vals[ 3 ] & 1 ); |
|
26
|
|
|
|
|
|
|
if( $header_vals[ 3 ] & 8 ) { |
|
27
|
|
|
|
|
|
|
$self->mirroring( 4 ); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
$self->has_sram( $header_vals[ 3 ] & 2 ); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
if( $header_vals[ 3 ] & 4 ) { |
|
32
|
|
|
|
|
|
|
my $trainer; |
|
33
|
|
|
|
|
|
|
$fh->read( $trainer, 512 ); |
|
34
|
|
|
|
|
|
|
$self->trainer( $trainer ); |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $mapper = ( $header_vals[ 3 ] & 240 ) >> 4; |
|
38
|
|
|
|
|
|
|
$mapper |= ( $header_vals[ 4 ] & 240 ); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
if( $mapper != 0 and $header_vals[ 0 ] <= 2 and $header_vals[ 1 ] == 1 ) { |
|
41
|
|
|
|
|
|
|
$mapper = 0; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->mapper( $mapper ); |
|
45
|
|
|
|
|
|
|
for( 1..$header_vals[ 0 ] ) { |
|
46
|
|
|
|
|
|
|
$fh->read( my $bank, 16384 ); |
|
47
|
|
|
|
|
|
|
$self->prg_banks->[ scalar @{ $self->prg_banks } ] = $bank; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
for( 1..$header_vals[ 1 ] ) { |
|
50
|
|
|
|
|
|
|
$fh->read( my $bank, 8192 ); |
|
51
|
|
|
|
|
|
|
$self->chr_banks->[ scalar @{ $self->chr_banks } ] = $bank; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $title; |
|
55
|
|
|
|
|
|
|
if( $fh->read( $title, 128 ) == 128 ) { |
|
56
|
|
|
|
|
|
|
$self->title( $title ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$self->clear_filehandle; |
|
60
|
|
|
|
|
|
|
return $self; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Games::NES::ROM::Format::INES - Loads data from a ROM in iNES format |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
This module loads the details of an NES rom in iNES format. An iNES file is |
|
76
|
|
|
|
|
|
|
layed out as follows: |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
+-----------+-----------------+---------+---------+ Header |
|
79
|
|
|
|
|
|
|
| NES\0x01a | [PC] [CC] F6 F7 | X X X X | X X X X | 16 Bytes |
|
80
|
|
|
|
|
|
|
+-----------+-----------------+---------+---------+ |
|
81
|
|
|
|
|
|
|
| | |
|
82
|
|
|
|
|
|
|
| Trainer (512 Bytes; Optional) | |
|
83
|
|
|
|
|
|
|
| | |
|
84
|
|
|
|
|
|
|
+-------------------------------------------------+ |
|
85
|
|
|
|
|
|
|
| | |
|
86
|
|
|
|
|
|
|
| PRG Banks (PC * 16384 Bytes) | |
|
87
|
|
|
|
|
|
|
| | |
|
88
|
|
|
|
|
|
|
+-------------------------------------------------+ |
|
89
|
|
|
|
|
|
|
| | |
|
90
|
|
|
|
|
|
|
| CHR Banks (CC * 8192 Bytes) | |
|
91
|
|
|
|
|
|
|
| | |
|
92
|
|
|
|
|
|
|
+-------------------------------------------------+ |
|
93
|
|
|
|
|
|
|
| | |
|
94
|
|
|
|
|
|
|
| Title (128 Bytes; Optional) | |
|
95
|
|
|
|
|
|
|
| | |
|
96
|
|
|
|
|
|
|
+-------------------------------------------------+ |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
PC: PRG bank count |
|
99
|
|
|
|
|
|
|
CC: CHR bank count |
|
100
|
|
|
|
|
|
|
F6: Various flags (Byte 6) |
|
101
|
|
|
|
|
|
|
F7: Various flags (Byte 7) |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 METHODS |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 BUILD( ) |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A L<Moose> method which loads the ROM data from a file. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Along with the L<base attributes|Games::NES::ROM/BASE ATTRIBUTES>, the following iNES specific attributes are |
|
112
|
|
|
|
|
|
|
available: |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=over 4 |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * id - iNES identifier: "NES\x1a" |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * trainer - Trainer data, if available |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=back |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=over 4 |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=item * Games::NES::ROM |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * http://wiki.nesdev.com/w/index.php/INES |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=back |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Brian Cassidy E<lt>bricas@cpan.orgE<gt> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2007-2013 by Brian Cassidy |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
141
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|