---------------------------------------
Date: Wed Jun 15 06:09:40 1988
From: JERRY MURPHY (aa300)
Subj: New Utility for Model 4

Mel Patricks' newest program for the Model 4 is CodeView/Arc. This file is the
text file from that archive, edited to remove several extraneous characters and
correct typos. If you have that archive, replace CODEVIEW/TXT with this info...
after removing my remarks, and the CFN prompts, of course.

------------------------------- CodeView/CMD ----------------------------------
                      Copyright 1988 by Mel Patrick
               A Z80 Machine Language Programmers Utility
-------------------------------------------------------------------------------

This utility is strictly for Z80 assembly language programmers.  In particular
those who find they have run out of room in their programs (like me when I
update the FastPlus BBS program). I'm  sure many have tried to cut down room in
their program only to  find that it's a lot bigger job than they expected.

HOW IT WORKS

CodeView works by doing a BYTE by BYTE check of any MACHINE  LANGUAGE program
and reporting all the repetitions above a preset  value. For example if in your
program you had two sets of bytes  exactly the same and they added up to more
than CodeView's preset  limit, it will be sent to the video/ printer. Each
location in  any program is checked.

Codeview will zero memory from 2600H to BFFFH before it starts  to load in the
selected program to check. This version resides at  memory location C000H. If
you need one which locates elsewhere,  let me know and I'll put one together foryou.

STARTING CODEVIEW

You have some options when using CodeView and you select these when you execute
the program (on the command line). The commands are as follows :

CODEVIEW,P#              ENTER

Where the P indicates you want HARDCOPY output and the # indicates you want to
specify the number of bytes which must match before it will be sent to the
video/printer.

From here you will be prompted for a /CMD program to check. Enter the file name
and press ENTER. You do NOT need the /CMD extension as it is assumed for
CodeView. It will be loaded and CodeView will report what the starting address
it found was. It will then ask you for the starting address to use. If you
press ENTER without any entry it will use the one it found when the program was
loaded. If you specify one, it will replace that one.

The last thing CODEVIEW will ask is for the ending address. This is the address
at which CodeView will stop checking and return to DOS READY.

All addresses must be input in HEX.

PRINTER OUTUT

CodeView will output to ANY 80 column printer with standard fan fold paper in
it. It will not work with a single page printer. When the output is done, it
will automatically issue a form feed code to the printer to eject the current
page. There is no top and bottom margins since you are really interested in
code duplicate sections and not pretty printing.

TYPICAL FORMAT

As CodeView checks the addresses, they will be displayed at the top right
corner of the video display. The window in which the matching bytes are shown
will scroll once it is full. Due to the speed of CodeView it will not scan the
keyboard to see if you want to stop, it will continue til its done, or you
press the RESET button. The same holds true if you are doing hardcopy output.
RESET is the only way to get it to stop.

A typical screen display would be something like this :

---------------------------------------------------------------------
  Address   Match   Total        Matching Byte List (17 max)
---------------------------------------------------------------------
  302A     3069     21 : EF AB C3 00 00 CA 58 49 12 44 55 66 EF ED B0
.....etc

Translated, it means that at address 302A there is 21 bytes of data (the 21 is
in DECIMAL not hex) and they match exactly with 21 bytes of data at address
3069. All addresses and data bytes are in HEX.

If you find a sequence such as the one shown above, you'll also find that the
next time, the address will increment by 1, when means it will be 302B and a
match will be found at 306A (add 1 to it to when it checks the whole program
again). In this the next line would look like this :

  302B    306A      20 : AB C3 00 00 CA 58 49 12 44 55 66 EF ED B0 F1

and so until it gets down to the limit which you set in the first place or the
default (which is set to 6).

NOTES

CodeView hums right along, but if you have a long program don't be surprised if
it takes a while to work through it. For fun if you want to check some of the
programs you already have go ahead. You'll probably be surprised at the amount
of code duplication that CodeView does find.

For myself, I always get a printer output and then from my assembler I get a
hardcopy assembly. Armed with that, I cross ref the address from CodeView to
the ASM listing and make a note of which sections I can convert to a
subroutine. I do the WHOLE program on paper before I actually start removing
sections from the source code and adding subroutines (I usually put all those 
in an INCLUDE file for access).

I checked FastPlus BBS and found that there were 62 sections which could be
replaced by a single subroutine (and a CALL to them). I managed to scrounge
back almost 250 bytes of memory, which may not sound like much, but that's
almost the same size as the message editing code I wrote (like a Basic line
editor). So it does make a difference.

If you have a Macro assembler, don't be surprised if there is a LOT of
duplication in your code (depending on how you define your macros). If you have
ever looked at IBM asm code, everytime they do anything (like open a file) they
duplicate the WHOLE code section (and error checking too!) each time in the
main code. It must be wonderful to have 640K to encourage people to write
sloppy code. Unfortunately (or fortunately depending on your point of view) we
Z80 programmers don't have that luxury.

Beware if you set the matching limit too low. You'll first off get a LOT of
information to the video/printer. Secondly, if you find say a 5 byte routine,
it won't pay to convert it to a subroutine. Why? Simple. You will have a total
of 10 bytes which you can remove from the two addresses that match BUT you have
to access the subroutines with a CALL so that leaves 3 bytes still in each
location. So where we had 10 bytes, we now only have 6, but wait, you still
need the subroutine and that was 5 bytes PLUS a RET byte so thats another 6.
Hence we now have a total of 12 bytes to do a routines which originally only
took 10. Watch that common mistake.

This program, while copyright by me, is released into the PUBLIC DOMAIN to
encourage other Z80 programs to take advantage of it and write better programs.

I have only written a Model 4 version of the program to date but if you want to
convert to a Model 3, the source code can be obtained from me directly for the
cost of a disk and mailing. I also run a BBS at (604) 594-7398, 8 bit word, No
parity, 1 stop, 24 hours, and it has quite a few Model 4 programs available.
You can call it at 300/1200/2400.

Obviously some non-programmers are going to try to use this program (its called
HUMAN NATURE). To them, if you want to see how well a program is written follow
the basic instructions for running this program and select a match count of
about 10. If the program you are checking starts duplicating like mad on the 
video/printer, you are either looking at real poorly written code, or you found
a large ASCII text section within the program and there is some duplication
(like a line of spaces which will show up as 20 in the BYTES LIST section).
Thats about all you'll be able to get out of it.

A good program to use in conjunction with CodeView is OverVue (a Model 4
machine language monitor). It can be found on most networks and my BBS as well.

