!pr2
PATCHER:  A General-Purpose Patch Installer.........Bill Morgan

My favorite new feature in Version 1.1 of the S-C Macro Assembler is the .PH directive.  When Bob first described the new directive to me, I didn't quite see how to use it.  Then he showed me a program like this one, and now I don't see how I did without it!

The directive .PH <expr> in an assembly causes the origin to be reset to <expr>, but the code continues to be stored in successive bytes of the same area as before.  The result is much like the following lines all rolled into one:

!lm+5
2000 LABEL
2010        .OR SOMEWHERE.ELSE
2020        .TA LABEL
!lm-5

The difference is that the above lines would close an open Target File, whereas .PH SOMEWHERE.ELSE continues to direct code into the same file.  The end of an offset block is marked with a .EP directive, that restores the origin to match the target address.

With this feature is so easy to assemble one program to create some patches and move them into place, all in one step.  Anyway, here's the general purpose PATCHER, with some dummy code to show it off.
!np
Notice that the object code columns show the bytes to be all over pages 3, 10, 20, and 30.  The labels in the Symbol Table show the same thing.  But, if you look around in memory, all this is in page 3.  Once you type $300G, the JMP instructions will be moved to their true destinations.

Bob's DOS Fast Load patches elsewhere in this issue are an ideal example of how to use PATCHER.  Here's all it takes:

!lm+5
!pp-3
1> Make the following changes to lines 1410-1430 of PATCHER:

     1410 P1.ORIGIN .EQ $BA69
     1420 P2.ORIGIN .EQ $BCDF
     1430 P3.ORIGIN .EQ $ACAF

2> Substitute Lines 1090-1160 of Fast Load for Line 1450 of PATCHER.

3> Substitute Lines 1210-1410 of Fast Load for Lines 1530-1550 of PATCHER.

4> Substitute Lines 1460-1590 of Fast Load for Lines 1630-1650 of PATCHER.

5> And substitute the following line for Lines 1740-1750 of PATCHER:
             .DA PATCH1
!lm-5
!pp0

Now you have a BRUNnable program which will quickly install the Fast Load patches into DOS.  And if you want to add other DOS patches to the same program, just tack them in between lines 1790 & 1800.

If you want to patch something running in a RAM card, like the Macro Assembler, you just need to add the following lines:

!lm+5
1082        LDA $C083
1084        LDA $C083

1315 .4     LDA $C080
1320        RTS
!lm-5

And that's how I expect to handle patches from now on.  Hope you find it useful!
