[203] | 1 | @rem = '--*-Perl-*--
|
---|
| 2 | @echo off
|
---|
| 3 | perl -x -S %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
|
---|
| 4 | goto endofperl
|
---|
| 5 | @rem ';
|
---|
| 6 | #!perl
|
---|
| 7 | #
|
---|
| 8 | # Add checksum byte to ROM image
|
---|
| 9 | #
|
---|
| 10 | # Use a size of 0 to skip this script entirely (file is not modified)
|
---|
| 11 | #
|
---|
| 12 | # On Windows, this file can be renamed to a batch file and invoked directly (for example, "c:\>checksum file size")
|
---|
| 13 | #
|
---|
| 14 |
|
---|
[376] | 15 | #
|
---|
[526] | 16 | # XTIDE Universal BIOS and Associated Tools
|
---|
| 17 | # Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 18 | #
|
---|
| 19 | # This program is free software; you can redistribute it and/or modify
|
---|
| 20 | # it under the terms of the GNU General Public License as published by
|
---|
| 21 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 22 | # (at your option) any later version.
|
---|
[526] | 23 | #
|
---|
[376] | 24 | # This program is distributed in the hope that it will be useful,
|
---|
| 25 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 26 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[526] | 27 | # GNU General Public License for more details.
|
---|
[376] | 28 | # Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 29 | #
|
---|
| 30 |
|
---|
[203] | 31 | ($ARGV[0] ne "" && $ARGV[1] ne "") || die "usage: checksum filename size\n";
|
---|
| 32 |
|
---|
| 33 | $desiredSize = int($ARGV[1]);
|
---|
| 34 |
|
---|
| 35 | if( $desiredSize == 0 )
|
---|
| 36 | {
|
---|
| 37 | exit( 0 );
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | open FILE, "+<".$ARGV[0] || die "file not found\n";
|
---|
| 41 | binmode FILE;
|
---|
| 42 | $cs = 0;
|
---|
| 43 | $last = 0;
|
---|
| 44 | $bytes = 0;
|
---|
| 45 | while( ($n = read( FILE, $d, 1 )) != 0 )
|
---|
| 46 | {
|
---|
| 47 | $cs = $cs + ord($d);
|
---|
| 48 | $cs = $cs % 256;
|
---|
| 49 | $bytes = $bytes + 1;
|
---|
| 50 | }
|
---|
| 51 | $oldBytes = $bytes;
|
---|
| 52 |
|
---|
| 53 | if( $bytes > $desiredSize - 1 )
|
---|
| 54 | {
|
---|
| 55 | die "ERROR: image is bigger than ".($desiredSize-1).": $bytes\n";
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[526] | 58 | $fixzero = chr(0);
|
---|
[568] | 59 |
|
---|
| 60 | #
|
---|
| 61 | # Compatibility fix for 3Com 3C503 cards. They use 8 KB ROMs and return 8080h as the last word of the ROM.
|
---|
| 62 | #
|
---|
| 63 | if( $desiredSize == 8192 ) {
|
---|
| 64 | if( $bytes < $desiredSize - 3 ) {
|
---|
| 65 | while( $bytes < $desiredSize - 3 ) {
|
---|
| 66 | print FILE $fixzero;
|
---|
| 67 | $bytes++;
|
---|
| 68 | }
|
---|
| 69 | $fixl = ($cs == 0 ? 0 : 256 - $cs);
|
---|
| 70 | $fix = chr($fixl).chr($cs);
|
---|
| 71 | print FILE $fix;
|
---|
| 72 | $bytes += 2;
|
---|
| 73 | } else {
|
---|
| 74 | print "Warning! ".$ARGV[0]." cannot be used on a 3Com 3C503 card!\n";
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[203] | 78 | while( $bytes < $desiredSize - 1 )
|
---|
| 79 | {
|
---|
| 80 | print FILE $fixzero;
|
---|
| 81 | $bytes++;
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | $fixl = ($cs == 0 ? 0 : 256 - $cs);
|
---|
| 85 | $fix = chr($fixl);
|
---|
| 86 | print FILE $fix;
|
---|
| 87 |
|
---|
| 88 | close FILE;
|
---|
| 89 |
|
---|
| 90 | open FILE, "<".$ARGV[0];
|
---|
| 91 | binmode FILE;
|
---|
| 92 | $cs = 0;
|
---|
| 93 | $newBytes = 0;
|
---|
| 94 | while( ($n = read( FILE, $d, 1 )) != 0 )
|
---|
| 95 | {
|
---|
| 96 | $cs = $cs + ord($d);
|
---|
| 97 | $cs = $cs % 256;
|
---|
| 98 | $newBytes++;
|
---|
| 99 | }
|
---|
| 100 | $cs == 0 || die "Checksum verification failed\n";
|
---|
| 101 |
|
---|
| 102 | print "checksum: ".$ARGV[0].": $oldBytes bytes before, $newBytes bytes after\n";
|
---|
| 103 |
|
---|
| 104 | __DATA__
|
---|
| 105 | :endofperl
|
---|