Program design, Program design -72, The last word 3.0 reference manual – Atari XL User Manual

Page 72

Advertising
background image

The Last Word 3.0 Reference Manual

12-72


One thing which has allowed LW to be crammed into such a small amount of code is
the placing of almost all the program's variables in Page Zero RAM. The entire upper
half of Page Zero is used by LW. This is made possible by the fact LW makes no calls
to the OS's floating point arithmetic routines, which require $D4-$FF for themselves. In
fact, LW doesn't even make any calls to CIO for screen output: it uses its own
sophisticated formatted print routine. The screen editor device is abandoned when the
program starts and only opened again upon exit to DOS. This use of page 0 instead of
absolute addresses makes LW between twenty and thirty percent smaller than it might
otherwise have been. It also means the program runs significantly faster than it would
had it relied more heavily on absolute addresses.

There are other techniques which save on code space. LW uses many memory
locations as flags, which are only ever on or off. These flags are tested using the 6502
"BIT" instruction, which means only bit 7 needs to be set or cleared. So instead of
storing 0 in the flag to clear it and 128 to set it, to clear it I use:

LSR <address>which puts a 0 in bit 7 with only 2 bytes of code.

To set it, I have used:

SEC
ROR <address>

Which is only 3 bytes (providing <address> is on page 0). The other bits in the byte are
of no significance, although occasionally more precision is required if both bits 6 and 7
of the byte are used. Bit 6 is also tested with the "BIT" command and will be
transferred to the overflow flag. Branching is done with "BVC" and "BVS". These
techniques don't really yield space savings when long strings of flags are being
cleared: it's as easy to load a 0 and store it in the flags. But when widely dispersed flag
sets/clears are necessary, the savings can soon mount up.

12.3 PROGRAM DESIGN


LW handles the text in memory in a special way in order to achieve its speed. While
many word processors hold text contiguously in memory, LW uses a pointer system to
ensure that the free memory in the buffer is always directly in front of the cursor.
Therefore, when you type, there is no slowdown in the editor regardless of the size of
the file. The text is moved through memory as you move the cursor through the it.
When the screen refresh routine hits the location of the cursor, it jumps over the free
memory in the buffer and displays the rest of the text, which is right at the top of the
buffer.

Although LW is written in compact assembly language, it is still a modular program.
Hardly any code is duplicated and

– to save space – subroutines are used instead of

in-line macro code. The reduction in code size achieved by using subroutines can be
considerable. In spite of the fact LW 2.1 was thou

ght to be a “finished” program in

2000, eight years later there were still significant space savings and efficiency gains to
be had from continuous revision of the source code.

This 80 column version of LW copes some 20 years after my first experiments with the
8-bit Atari. I began programming in BASIC, then I moved on to C, and finally to
Assembler. Having looked at CC65, Action!, PL65, and many other languages, I
honestly think that machine code is still the best language to use when compactness is

Advertising