!lm12
!rm75
Toggling Upper/Lower Case in the S-C Macro Assembler.........
!rj
Steven Mann
Psychology Dept.
Univ. of So. Dakota
P. O. Box 7187
Grand Forks, ND 58202

!lj
I have made the necessary modifications to the assembler (and to my Apple) that allow me to enter lower case characters in my source programs, but have found that I like to have all upper case in certain sections (the labels and opcodes) and mixed (mostly lower) case only in the comment field.  In order to do accommodate this most effectively, I wanted to be able to toggle back and forth from upper to lower case while I was entering my source code.

The simplest solution for me was to patch the assembler to accept one of the escape key sequences as an upper/lower case toggle.  From back issues of AAL I was able to determine that a table of address vectors for the escape keys A-L is maintained from $1467 thru $1482 ($D467 thru $D482 in the language card version).  Each two-byte entry is the address-1 (low byte first) of the routine that will handle that particular escape sequence.

Certain of the sequences are already taken (e.g. ESC L loads a disk file; ESC I,J,K, and M move the cursor, etc.)  Since I don't use the ESC A,B,C,D cursor moves, I selected the ESC A sequence as the code for the case toggle.  I also used ESC C for "CATALOG", as suggested by Bill Morgan some months back in these pages.

Implementation of the toggle is accomplished with the following patches to the HELLO program (for the RAM version of the assembler.)  First, line 50 should be changed to:

!lm+5
50 PRINT A: IF A=1 THEN PRINT CHR$(4)"BLOAD S-C.ASM.MACRO"
   :GOSUB 200: CALL 4096
!lm-5

The subroutine at 200 is as follows:

!lm+5
197 REM
198 REM ESC A TOGGLES UP/LOW CASE
199 REM
200 POKE 5229,109:POKE 5230,165
210 FOR I=1 TO 9:READ J:POKE 48350+I,J:NEXT
220 DATA 173,22,16,73,255,141,22,16,96
230 RETURN
240 REM
250 REM ROUTINE RESIDES AT $BCDF
260 REM
270 REM CODE IS AS FOLLOWS:
280 REM
290 REM     LDA $1016
300 REM     EOR #FF
310 REM     STA $1016
320 REM     RTS
330 REM
!lm-5

Note that I put the patch code at $BCDF, which is in an unused area inside DOS 3.3.  If you have already used this area for other purposes, you can tack the patch on to the end of the assembler image instead.

The actual code is very simple.  The upper/lower case flag is stored at $1016 and is either a $00 or a $FF (in binary all zeros or all ones.)  Toggling the flag involves loading the current flag and EORing it with #$FF.  This will cause all set bits to be cleared and all clear bits to be set, so the zeros become ones and the ones become zeros.  Thus, an #$FF byte becomes a #$00 or a #$00 becomes an #$FF.  The new flag value is then stored back in $1016.

For the language card version the program is basically the same, but slightly longer due to the need to first write enable the language card.  The code looks like this:

!lm+5
PATCH   LDA $C083       Two of these in succession
        LDA $C083       write-enable the card
        LDA $D016       Get the flag
        EOR #$FF        Complement it
        STA $D016       Save the new flag
        LDA $C080       Write protect the card
        RTS
!lm-5

I put the code in the same place as in the RAM version ($BCDF) and put it into memory from the LOAD LCASM exec file which loads the assembler onto the card.  Two lines need to be added to the file.  Between lines 1070 and 1080 (assuming your version has not been modified) you need to place these two lines:

!lm+5
1072 D469:DE BC
1074 BCDF:AD 83 C0 AD 83 C0 AD 16 D0 49 FF 8D 16 D0 AD 80 C0 60
!lm-5

The first line places the address of the case toggle handler in the escape vector table and the second line contains the assembled source code listed above.  If you are not sure how to modify the LOAD LCASM file see the step by step description given in the May 1982 AAL (page 3).

After you have made the patch, experiment with the toggle.  One particularly valuable feature is that you can toggle the case within a single line as you enter the line.  This means that you can enter the label and opcode in upper case, tab over to the comment field, toggle the case flag, and then enter your comment in lower case.  

I have found using the case toggle to be easy while improving the appearance and readability of my source listings.  The only problem I have encountered so far is that the flag can not be toggled from within the edit mode (either case can be used in the edit mode, but you can't change the case in the middle of editing.)  If any of you find a way to add this to the assembler be sure to let me know.

[ P.S.  If you haven't put in the automatic catalog yet, here is an easy way.  Add the following line to your LOAD LCASM file: 

     1076 D46D:6D A5

and then ESC C will do a catalog as long as you don't mind having to hit return at the end of the catalog.  For the motherboard version, add:

     205 POKE 5225,222: POKE 5226,188

in the subroutine I've added to the HELLO program. ]

{Ouch!  Why didn't I think of that?  One caution:  With this method ESC C will do a CATALOG even if you are in the middle of typing a line. . . . Bill Morgan}
