Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- # display help message when no argument
- if (@ARGV < 2) {
- print "usage: $0 [binary] [line] [(step)]\n";
- exit;
- }
- my $filename = $ARGV[0];
- my $line = $ARGV[1];
- my $step = 0;
- my $filesize = -s $filename;
- my $column = 16;
- my $address = 0x700;
- my $buf;
- my $j;
- #check arguments
- if (@ARGV >= 3) {
- $step = $ARGV[2];
- }
- if ($step <= 0) {
- $step = 10;
- }
- # load file
- open (FILE, '<' . $filename) or die "$!";
- binmode FILE;
- read (FILE, $buf, $filesize) or die "$!";
- close(FILE);
- # convert
- my @data = unpack('C' . $filesize, $buf);
- for (my $i = 0; $i < $filesize; $i += $column) {
- printf("%d POKE #%03X,#%02X", $line, $address + $i, $data[$i]);
- my $remain = $filesize - $i;
- if ($remain > $column) {
- $remain = $column;
- }
- for (my $j = 1; $j < $remain; $j++) {
- printf(",#%02X", $data[$i + $j]);
- }
- printf("\n");
- $line += $step;
- }
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement