MacLarry
Volume Number: 16
Issue Number: 2
Column Tag: Programming
By F.C. Kuechmann, Vancouver WA
An M68HC11 S-record dissecting kit in CodeWarrior
S-record files are used to transfer code from development systems to PROM and
EPROM programmers. This article discusses the implementation and use of MacLarry,
an S-record dissecting program. MacLarry allows you to view the contents of
S-records in several formats.
What is an S-Record File?
Programmers who are confined to the desktop world experience code movement in
terms of disk file to memory and back to disk. They are often unfamiliar with
hex-format files that are used to transfer program code from a desktop development
system to an EPROM (Erasable Programmable Read-Only Memory) or PROM
programmer for use in an embedded controller. Common examples of embedded
controllers include the M68HC16 in a Jaz drive, and the M683xx-series inhabiting
Palm Pilot PDAs and anti-lock brake systems (ABSes) in General Motors cars. In each
of these cases the program code probably spent some time in S-records.
How do we use one?
In a typical instance you might be writing a BASIC11 program for a Micromint
RTC-HC11 stackable module to be used to control a gate and barrier system at a fish
hatchery. After the usual multiple-pass write-debug-modify-debug cycle you send an
"ESAVE" command to the RTC-HC11 via the RS-232C serial port connection (usually
the modem port on a Mac). The RTC-HC11, after a brief delay, churns out the program
in its memory in the form of S-records. Using a terminal program you capture the
records to a text file, clean up any garbage with an editor, and transfer the file to an
EPROM programmer via a serial port. When the file has been written to a 27256
(32k-by-8) EPROM by the programmer, you type an "AUTOST" command to the
RTC-HC11, shut off its power, and replace the resident EPROM with the one you've
just programmed. Restore the power and the program autostarts and runs.
At another time you might submit the MC68HC05b6 code for your smart toaster to
Motorola in the form of an S-record file so that the processors for your next
production run can be masked with the code during manufacture.
How is MacLarry Useful?
In the normal course of embedded development MacLarry is probably unnecessary. You
already have the assembler sourcecode. But what if old friend Murphy (of Murphy's
Law fame) visits and destroys all copies of your source, leaving you with only an
S-record file of your code? MacLarry could be very useful in helping recover your
source.
Perhaps, after getting so involved in programming and testing that you neglected to
clearly label the files, you're merely trying to determine which S-record file holds
the most recent version, or a particular version, of your code.
Or what if you're just curious about some S-record files you found and downloaded
from the net? MacLarry again comes to the rescue.
What does an S-record look like?
The S-record format originated at Motorola and is commonly used with code for
processors made by that company, including the extremely popular MC68HC05 used in
cellular phones and pagers, and the M68HC11 series. S-records are similar in
concept to the more common Intel hex format with a few important differences in
detail. An S-record line consists of a two-character header, a two-character hex
bytecount that gives the number of bytes in the record, a two-byte hex address,
bytecount minus three hex bytes of code, and a one's complement hex checksum. The
S-record files that MacLarry deals with have "S1" headers on all lines but the last,
which has an "S9" header and no significant content. The components of a line with an
"S1" header might look like Figure 1.
Figure 1. S-record format.
"S1" is the header. The next two digits (13) indicate in hex the number of bytes to
follow in the line, including a four-digit address and two-digit checksum. The "0000
is the address and is followed by 10 (hex, 16 decimal) bytes of data and the "BF
checksum.
MacLarry the Dissector
The CodeWarrior Pascal program MacLarry can be used to dissect M68HC11
S-records in order to recreate assembler sourcecode. MacLarry dissects 68HC11
S-records three ways:
• Asciification - isolates printable ASCII characters (range 32-126).
• Disassembly into mnemonics with address and data fields.
• Disassembly without address and data fields for ready conversion to
assembler sourcecode.
Asciification or dumpster?
What is "asciification"? This method of dissecting S-record files prints characters in
the ASCII range 32-126 beside the address and hex data, replacing characters outside
that range with dots. This sort of output is commonly called a "hex dump" when derived
from a binary file. But what is it if you start with a hex file to begin with? Can you
hex dump a hex file? "Dumpster" might be a more descriptive name than "asciifier".
Whatever it's called, it simplifies locating embedded text strings and command tables
in the target file.
The output files
A MacLarry dissection creates three files, one each with the extensions "asc", "dis" and
"src" appended to the original filename minus the usual "S19" extension. Thus if the
S-record filename is JudithWhatley.S19, the output files will be JudithWhatley.asc,
JudithWhatley.dis and JudithWhatley.src.
Sample output
Listing 1a shows the asciification of parts of the file BASIC113.S19, containing
version 1.13 of BASIC11. BASIC11 is a freeware integer BASIC interpreter for the
M68HC11. Versions of this BASIC are distributed by companies such as New Micros
Inc, and MicroMint Inc with some of their M68HC11-based stackable control
computers. Generic versions that aren't modified specifically for a given
manufacturer's boards are also freely available via the internet. Some URLs can be
found at the end of this article. The listing shows the identity text and copyright notice.
______________________________
Listing 1a.
Ascifying bas113.s19
Start 19:38:41
Finish 19:39:08
E000 0000 7EED30BDECD6B6600881552603BDF116 ~.0....'..U&....
E010 0010 BDE0608EDFFF0E4F5FDD3ADD3FDD41BD ..'....O_.:.?.A.
E020 0020 E0A37F00197F00187F001DBDE0F4BDE0 ................
E030 0030 B3BDE053BDEE0F1A83000026D6DE0EDF ...S.......&....
E040 0040 2FBDE1167D001926CA20D7DE2F6F00DF /...}..&. ../o..
E050 0050 0E20C0BDE38C81202605BDE39520F439 . ..... &.... .9
E060 0060 CEE0667EE10B0D0A0D0A424153494331 ..f~......BASIC1
E070 0070 312076312E31330D0A436F7079726967 1 v1.13..Copyrig
E080 0080 687420313938352C313938362062790D ht 1985,1986 by.
E090 0090 0A476F72646F6E20446F7567686D616E .Gordon Doughman
E0A0 00A0 0D0A00CEE0A97EE10B0D0A5245414459 ......~....READY
Listing 1b reveals a table of BASIC11 commands, which are presumably used in
tokenizing input.
Listing 1b.
E200 0200 813A2607867ABDE3A020B3810D270586 .:&..z... ...'..
E210 0210 027EEA4E867DBDE3A0DC0283DE00CEDE .~.N.}..........
E220 0220 00E7023944415441000CE3BC4C455400 ...9DATA....LET.
E230 0230 01E3DC52454144000DEA0E524553544F ...READ....RESTO
E240 0240 5245000EE3BB474F535542000FE3B247 RE....GOSUB....G
E250 0250 4F544F0012E3B24F4E54494D450025E8 OTO....ONTIME.%.
E260 0260 894F4E4952510026E8894F4E50414343 .ONIRQ.&..ONPACC
E270 0270 0028E8A94F4E0013E83B52455455524E .(..ON...;RETURN