!pr0
What That Code Did.........................Bob Sander-Cederlof

Way back in August 1981 I published a short article by John Broderick titled "What Does This Code Do?"  Well, John never did tell us.  But in the May 1984 Nibble, page 115, he finally has let the cat out of the bag.  I think this article has probably been banging around the Nibble office for some time now, because John hasn't done anything with Apple's in quite a while.  He developed a super fast accounting program in Apple II assembly language, then re-wrote the whole thing for the Sage 68000-based system.  Last I heard he was in the IBM world.

The code he gave us three years ago was five bytes long:

             BRK
             PLA
             PLA
             PLA
             RTS

As published in Nibble, it is a little longer:

       BREAK BRK
             NOP
             PLA
             PLA
             JSR $FF3F
             RTS

Boiling it all down, John used this code during debugging sessions.  By putting a JSR to the 8-byte program he can effect a clean breakpoint.  Clean, in that he can use the monitor "G" command to continue execution after the BRK.

When JSR BREAK is executed, the BRK opcode will send Apple into the monitor and display the five registers.  Their contents will have been saved at $45 thru $49.  The address of the first PLA will also be saved.  Typing the monitor "G" command will continue execution at that PLA.  The two PLA's will pop off the return address the G command put on the stack, leaving it as it was before the BRK.  The JSR $FF3F will restore the A-register, which the two PLA's clobbered.  The the RTS will return right after the JSR BREAK which started this paragraph.

The original five-byte version was both confusing and erroneous.  Confusing, because the PLA immediately after the BRK is never executed.  BRK seems like a two-byte opcode to the 6502, so the saved address skips over the following byte.  Erroneous, because the A-register has been changed by the time the RTS is executed.  I think I would amend both of his versions to this:

       BREAK  BRK
              NOP
              PLA
              PLA
              LDA $45
              RTS
