!pr0
Assembly Listing Into a Text File...................Bill Morgan

"That's not a bug, that's a feature!"  We've all heard (or said?) that before, but this time it really seems to be true.  We have just discovered an undocumented feature in Version 1.1 of the S-C Macro Assembler.

I was trying to see if a program would assemble, and wanted the assembly to be as fast as possible.  For some reason I didn't want to do the obvious thing and just switch the listing off, and using a .TA wasn't convenient.  So, I stuck a .DU (DUmmy) directive at the beginning of my program, and a .ED (End Dummy)at the end, figuring that would eliminate the time spent writing object code to the disk.  When I typed ASM the assembler paused a moment for pass one, then started listing the beginning of the program.  But, when the assembler got to the .TF directive the listing stopped and the disk drive started spinning.  That wasn't supposed to happen!

When the assembly finished, and the drive stopped turning, I CATALOGed the disk to see what had happened.  There was a Binary file, with the filename from my .TF directive, but instead of being much smaller that the source file, it was about twice as big.  What could be in that file?

It seemed dangerous to just BLOAD a file that shouldn't exist, so I booted up a disk zap program and inspected the disk.  That Binary file contained the text of the assembly listing, starting with the .TF line.  Also, the file had no load address and length bytes.  The first four bytes were "A0 A0 A0 A0", or the ASCII codes for four spaces.  If I had tried to BLOAD the file, it would have loaded at $A0A0, which would have immediately clobbered DOS!

I was preparing a note to warn everybody not to use .TF within a .DU - .ED block, when Bob reminded me of how often we WANT an assembly listing on a Text file, to read into the S-C Word Processor and merge into an article.  Why didn't I find out what the Word Processor would make of this file?  Well, it read the file just fine, but discarded the first four bytes, since it expects load address and length bytes in a Binary file.  In most cases that is no problem, since the first line is the .TF <filename> directive, and will be discarded anyway.

Now we have a Binary file containing the text.  That's fine with the S-C Word Processor, but what about other programs, that might require Text files?  As it happens, the Macro Assembler creates a Target File as a Text file, then updates the Catalog to turn it into a Binary file.  All we have to do is patch the assembler to prevent that change in the file type.  That is only a 1-byte patch.

So, all it takes to send the assembly listing to a disk file is to begin the program with a .DU and a .TF, and end it with a .ED.  If you want a real Text file, you only have to patch one byte in the assembler.
!np
To make a long story short, here's how to create a Text file containing an assembly listing:

!lm+3
!pp-3
1) At the beginning of your program, put the lines:

!lm+5
0000       .DU
0001       .TF LISTING
!lm-5

   and at the end put:

!lm+5
65535      .ED
!lm-5

2) If there is already another .TF directive in your program, insert a "*" at the beginning of the line, to make it into a comment.

3) Enter one of the following patches:

!lm+5
$1000 Versions: $29DF:0
$D000 Versions: $C083 C083 EAF9:0 N C080
!lm-5

4) Type ASM.

5) And restore the patched location:

!lm+5
$1000 Versions: $29DF:4
$D000 Versions: $C083 C083 EAF9:4 N C080
!lm-5
!lm-3
!pp0

Now you can load LISTING into a word processor, delete the first and last lines, and do whatever you want with it!

I tried creating an EXEC file to do all those steps automatically, but ran into trouble.  When the assembly ends the EXEC file loses control, and the Text file LISTING doesn't get closed.  When I can solve that one I'll let you know.
