-
Notifications
You must be signed in to change notification settings - Fork 4
/
dreplace_mmb.pl
executable file
·48 lines (34 loc) · 1.22 KB
/
dreplace_mmb.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
use strict;
# Beeb Utilities to manipulate MMB and SSD files
# Copyright (C) 2012 Stephen Harris
#
# See file "COPYING" for GPLv2 licensing
use FindBin;
use lib "$FindBin::Bin";
use BeebUtils;
@ARGV=BeebUtils::init(@ARGV);
my $dest=$BeebUtils::BBC_FILE || 'BEEB.MMB';
die "$dest does not exists\n" unless -e $dest;
die "Syntax: $BeebUtils::PROG [-f MMB_file] file1.mmb cat_number\n" unless @ARGV == 2;
my $source=$ARGV[0];
my $cat=$ARGV[1];
die "Catalogue must be a number\n" unless $cat =~ /^[0-9]+$/;
die "Catalogue must be 0-15\n" if $cat < 0 || $cat > 15;
# Check file exists and looks like it's an MMB file (right size)
my @s=stat($source);
die "Could not stat $source: $!\n" unless @s;
my $len=$s[7];
die "$source is the wrong size; is it an MMB?\n Found $len, should be " . $BeebUtils::MMBSize . "\n" unless $len == $BeebUtils::MMBSize;
# OK everything looks sane...
my $fh=new FileHandle "+< $dest";
die "Can not open $dest for updating\n" unless $fh;
binmode($fh);
my $image;
my $src=new FileHandle "<$source";
die "Error opening $source: $!\n" unless $src;
sysread($src,$image,$BeebUtils::MMBSize);
close($src);
sysseek($fh,$cat*$BeebUtils::MMBSize,0);
syswrite($fh,$image);
print "$dest updated\n";