!pr2
!lm12
!rm75
Blinking Underline Cursor Routine..................Bill Linn

Early users of the ES-CAPE Applesoft Editing system (formerly known as AED II) have really come to appreciate the blinking underline cursor -- it simply doesn't tire the eyes as much as the standard flashing blank does.  With the following subroutine, you can add this special touch to your own assembly language or BASIC programs!

The subroutine hooks into the monitor keyboard input vector at $38 and $39.  Each time the monitor RDKEY subroutine is called, my KEYIN subroutine gets control.  If the character on the screen at the cursor position is not an underline, I alternate the display of an underline and the original character every 1/4 second.  If the original character was an underline, I alternate it with a blank.  (If I alternate an underline with an underline, it is difficult to see anything happen!)

Lines 1210-1250 store the KEYIN subroutine's address in the keyboard input vector.  When a request for a key press is made by an Applesoft INPUT command, for example, we get control at line 1270.  The A-register has the current screen character.  I save the A- and X-registers, because KEYIN must exit with the original values unchanged.

Lines 1290-1320 test the current screen character to see whether it is already an underline or not.  If it is, I use a blank for the alternating character.  Otherwise, I use the original screen contents for an alternating character.  I push the alternating character onto the stack.

Lines 1330-1500 do the alternating.  I look at the character on the screen:  if it is an underline, I substitute the alternating character; if not, I store an underline.  The lines 1430-1500 delay for about 1/4 second before the next alternation.  If a keypress occurs, the loop ends by branching to ".5" at line 1540.  You may wish to vary the blink rate by changing the value loaded into the Y-register at line 1430.

When a key is pressed we end up at line 1540, where I pop the alternating character off the stack.  The I call the monitor bell subroutine for a short (10 half-cycles) bell.  This makes an audible "click" for user feedback.  (If you don't appreciate clicking keyboards, just delete lines 1550 and 1560.)  Then I restore the Y-, X-, and A-registers to their orignal values, and jump into the monitor's KEYIN subroutine at $FD26.  The monitor restores the original character to the screen, and returns with the keypress value in the accumulator.

I have set the subroutine origin to $300, but you can assemble it anywhere you like.  In fact, it will run anywhere you put without reassembly, just so you load the correct address into $38 and $39 in the HOOK routine.
!np
After assembly, assuming it is origined at $300, you can BSAVE it with "BSAVE B.UNDERLINE,A$300,L$3C.  Then to activate this routine from Applesoft, just BRUN the file B.UNDERLINE.  All keyboard input through the standard monitor RDKEY subroutine ($FDOC) or Applesoft GET and INPUT statements will be prompted by the underline cursor.  An "IN#0" will restore the familiar flashing blank.  Have fun!
