converting ascii hex to binary (was Re: [sdiy] TMS7000 disassembler ? )

Andre Majorel amajorel at teaser.fr
Tue Feb 26 17:43:44 CET 2002


On 2002-02-25 16:44 -0500, CHoaglin at aol.com wrote:

> while we're on the subject of disassemblers, does anybody know how to go 
> about converting an ASCII hex
> 
> ie: <ADDRESS>-----<HEX>------<ASCII REPRESENTATION>
> 
> file into a raw binary file containing only the binary representation of the 
> hex?
> 
> I'm trying to disassemble some 6803 code I dumped from a ROM, and this is a 
> major stumbling block. I've found a number of utilities to go from binary to 
> ASCII, but not the other way round.

As Grant pointed out, there should be something available with the
EPROM programmer. You can always try this quick hack :

#!/usr/bin/perl -w
use strict;
foreach my $infile (@ARGV)
{
  open IN, $infile or die "$infile: $!\n";
  my $outfile = "$infile.bin";
  open OUT, ">$outfile" or die "$outfile: $!\n";
  binmode OUT;
  while (defined (my $l = <IN>))
  {
    next if $l =~ /^\s*$/;
    $l =~ /^[[:xdigit:]]+((?:\s+[[:xdigit:]]{2})*)\s/;
    die "$infile($.): bad format\n" if ! defined $1;
    my @bytes = split ' ', $1;
    print OUT map (pack ("H2", $_), @bytes);
  }
}

-- 
André Majorel <URL:http://www.teaser.fr/~amajorel/>
std::disclaimer ("Not speaking for my employer");



More information about the Synth-diy mailing list