 
*   ED5/CURSR   40 col        Jul / 19 / 93
*---------------------
*   Enhanced
 
*  Cursor flash routine
*---------------------------------
*  Enter with  R9 = screen pointer
*              R0 = <cursor,char>
*  Destroys    R8,R9
 
FLACSR EQU  $
CLRFLA CLR  R8                Clear counter for cursor flash
CLRTIM MOVB R8,@TIMER         Clear the timer from MSB
CHKTIM CB   @TIMER,@B06       Has timer reached 1/10th sec.?
       JL   SCANIT            No, so go scan keyboard
 
       INC  @DELAY            Inc DELAY ctr every 1/10th sec
       INC  R8                Inc FLASH ctr every 1/10th sec
       C    R8,@FLRATE        Is it time to flash cursor?
       JL   CLRTIM            No, so clear the timer
 
*  Flash cursor
 
       BLWP @SETVDW           R9 = cursor vdp address
       MOVB R0,@VDPWD         Write to screen
       SWPB R0                Swap cursor and chr
       JMP  CLRFLA            Go clear flash counter
 
*  Check keyboard
 
SCANIT BLWP @SCANKY           Check keyboard
       SZCB @ANTI20,@GPLST    Isolate GPL cond'n bit
       JNE  NEWKEY            Yes, it was set
 
       CB   @KEYRT,@BFF       Is any key down?
       JEQ  CHKTIM            No, so loop
 
CHKDEL C    @DELAY,@TENS      Has delay reached 1 second?
       JL   CHKTIM            No, so loop
 
       MOV  @TENS,@DELAY      Yes, set delay to 9/10ths sec
       JMP  PRCKEY            Go process key
 
NEWKEY CLR  @DELAY            Clear the 1 sec delay counter
PRCKEY ABS  @UPCASE           Check if UPcase ordered
       JEQ  CNVL20            All cases allowed
 
*  Check for lower case
 
CNVLC  LI   R8,KEYRT          Do it for key return
CNVLC8 CB   *R8,@LCA          Below "a" ?
       JL   CNVL20            Yes
       CB   *R8,@LCZ          Above "z" ?
       JH   CNVL20            Yes
 
       SB   @DSPACE,*R8       Convert to UC
CNVL20 RT
 
*  Upcasing keyscan / Wait for <escape>
*--------------------------------------
*  Call as  BL  @KWAIT  for <esc> only
*           JMP $-4
*           <esc> code
*    or as  BL  @KWAIT  for any key
*           NOP
*           <any key> code
*  SCANKY   uses BUFMWS
 
 
KWAIT  EQU  $
       BLWP @SCANKY           FW keyscan
       LI   R8,KEYRT          Fetch key return
       CB   *R8,@BFF          No key ?
       JEQ  KWAIT             Wait more
 
       CB   *R8,@CTRLC        <^c> ?
       JEQ  KWAIT2            Yes
       CB   *R8,@B0F          <f9> ?
       JNE  CNVLC8      KSCANI            No - try again
 
KWAIT2 INCT R11               Escape exit steps over JMP following
       RT
 
*  Two-way case shifting
*-----------------------
 
DNCAS  LI   R9,'AZ'           Upper case comparisons
       LI   R15,' *'          Lower to upper correction
       JMP  CASE1
 
UPCAS  LI   R9,'az'           Lower case comparisons
       LI   R15,>E027         Upper to lower conversion
CASE1  CB   *R4,R9            Check *CURADR
       JL   RGTAR             Out of range
       SWPB R9                Other end
       CB   *R4,R9            Check *CURADR
       JH   RGTAR             No interest again
 
       AB   R15,*R4           Make correction
RGTAR  INC  R2                Advance CURSOR
       RT
 
UCA    EQU  DNCAS+2
UCZ    EQU  DNCAS+3
LCA    EQU  UPCAS+2
LCZ    EQU  UPCAS+3
ASTRIX EQU  DNCAS+7           Don't waste a data byte
SQUOTE EQU  UPCAS+7
 
 
*  Scan keyboard as BLWP routine
*-------------------------------
*  BLWP vector in BUFMGR block
 
SCAN10 LWPI GPLWS             Must be in GPL workspace
       ABS  @NOINTR           Set by auto wordwrap ?
       JNE  SCAN20            Yup - skip interrupts this once
 
       LIMI 2                 Give the timer a chance to INC
WTWO   EQU  $-2
TWO    EQU  $-1
READ   EQU  $-1
       LIMI 0                 That's enough chance
SCAN20 CLR  @NOINTR           Make sure it is cleared
       BL   @>000E            Console keyboard scan
       LWPI BUFMWS            Restore WSP for return
       RTWP
 
*  Margin checker / Delay / Sound
*--------------------------------
 
MRCHEK EQU  $
       STWP R0                R0 constrained for delay-only path
       MOVB @KEYRT,R10        Copy key return
       JLT  DELXX             <ctrl> key
       CB   @DSPACE,R10       Below blank ?
       JH   DELXX             Must be <fctn> key
 
       MOV  @RMRG,R10         Copy right margin
       S    R2,R10            Compare current Cursor
       JEQ  MEXIT             On margin - no delay & don't bug sound
 
       C    @RMGIN,R10        At inset ?    >FFD8
       JNE  DELXX             No bell then - delay only
 
*  Sound or delay
*----------------
 
BEEP   LI   R8,MBSDAT         Margin bell sound list
SNDENT LI   R0,SOUND          Sound chip
       MOVB *R8+,*R0          First byte
       NOP                    WASTE time
       MOVB *R8+,*R0          Second byte
       NOP                    WASTE time
       MOVB *R8,*R0           Third byte
DELXX  LI   R10,>1200         Time delay / Sound duration
DELVAL EQU  $-2               Written in from FW
DELYY  DECT R10               Count down
       JGT  DELYY             More to go
 
       MOVB @SNDATA+3,*R0     Voice #1 terminator for all
MEXIT  RT
 
*  Make unpleasant warning noise
*-------------------------------
 
HONK   LI   R8,SNDATA         Honk data
       JMP  SNDENT
 
BEEPL  LI   R8,LBDAT          Little bleep
       JMP  SNDENT
 
*  High-bit toggle - use CMARKR as flag
*--------------------------------------
 
HIBIT  EQU  $
       AB   @H80,@CMARKR      High bit mask
       JMP  BEEP
 
*  Line marker <fctn-;>
*----------------------
 
MARKIT EQU  $
       MOV  R1,@MKTBL
       JMP  BEEP
 
*  Auto insert routine used by wordwrap
*--------------------------------------
 
AUTOIN EQU  $
       MOV  R11,@AUTXIT+2     Save return address
       MOV  @CMDRT,R11        Illegal in command mode
       JNE  AUTXIT
 
       SETO @CRFLAG           Turn flag on
       CLR  @TOPPAR           No longer at top of paragraph
       MOV  R4,R8
       CB   @KEYRT,@DSPACE
       JEQ  AUTO15
 
       CLR  R6                Word wrap length
       DEC  R8                Don't count this character.
       MOV  @RMRG,R14
       S    @LMRG,R14         Constructs current line length
AUTO05 CB   *R8,@DSPACE       Find last blank
       JEQ  AUTO20            Found it
 
       INC  R6                Count character
       C    R6,R14            Out of Range?
       JHE  AUTO15            Yes, don't wrap
 
       DEC  R8                Back up to next char
       JMP  AUTO05            Look for next blank
 
AUTO15 CLR  R2                Can't wrap word, home cursor
       MOVB R5,*R4
       BL   @UPDATE           Update this line
       BL   @INSL50           Insert blank line below
       BL   @SCROLL
       JMP  AUTXIS
 
AUTO20 LI   R9,TEMPM6
       A    @LMRG,R9          Adjust wrap for left margin
       INC  R8                Skip blank
       MOV  R8,R11            R8=Addr of word to wrap
       MOV  R6,R10            R6=Length of word to wrap
       JEQ  AUTO35
 
AUTO30 MOVB *R8+,*R9+         Wrap word to next line
       DEC  R6
       JGT  AUTO30
 
AUTO35 MOVB R5,*R9            Output this character
       INC  R10
AUTO40 MOVB @DSPACE,*R11+     R11 -> Addr of wrapped word
       DEC  R10               Blank out rest of current line
       JGT  AUTO40
 
       S    @TADR,R9          Calculate new cursor position
DSIX   EQU  $+2
       AI   R9,6              Allow for line numbers
       MOV  R9,R2             Update Cursor
       BL   @BUMPC            Bump cursor
AUTO50 SETO @NCHAR            Enter routine comes here
       BL   @UPDATE
 
*  Entry from EnterKey
 
AUTO60 INC  R1                Cline
       BL   @INSLIN           Insert line (Tempbf)
       MOV  @LINADR,R4        Update Buffer pointer
       A    R2,R4             Add Cursor
       AI   R4,86             Adjust Curadr
       BL   @SCRL03           Adjust screen pointers
AUTXIS SETO @NOINTR           Cancel interrupt on next scan
AUTXIT B    @>0               Exit
 
*  Routines to handle cursor
*---------------------------
 
*  Cursor left
 
LFTAR  EQU  $
       DEC  R2                Back up Cursor
       RT
 
*  Main cursor positioning routine
*---------------------------------
*  CURSOR == R2
 
BUMPC  EQU  $                 Finds window for current cursor
       ABS  @GOLF             Margin release set ?
       JEQ  BUMP00            No
 
       LI   R8,FORMO          Point to current margins
       C    R2,*R8            Cursor to left
       JLE  BUMP00            No - not yet
 
       C    R2,@2(R8)         Too far right then
       JHE  BUMP00            Not yet
 
       MOV  *R8+,@LMRG        Restore working LMRG
       MOV  *R8,@RMRG         And RMRG from table also
       CLR  @GOLF             Reset margin release flag
 
*  Continue after margin release check
 
BUMP00 C    R2,@LMRG          Where is cursor ?
       JLT  BUMP07            To left
       C    R2,@RMRG          Cursor ?
       JGT  BUMP09            Not to the right
 
BUMP05 C    R2,*R7            On this screen ?
       JLT  BUMP01            Definitely no
       C    R2,@2(R7)         Maybe ?
       JLE  BUMP10            Yes
 
BUMP01 LI   R7,WTOP
BUMP06 C    R2,@2(R7)
       JLE  BUMP10
 
       C    *R7+,*R7+
       MOV  *R7,*R7
       JLT  BUMP01
       JMP  BUMP06
 
BUMP07 MOV  @LMRG,R2
       JMP  BUMP05
BUMP09 MOV  @RMRG,R2
       JMP  BUMP05
 
BUMP10 MOV  R2,R4             Calculate cursor address
       A    @LINADR,R4
       RT
 
*  Horizontal window control
*---------------------------
*  Line & Mode switch
 
LMODE  EQU  $
       ABS  @LINF             Toggle line mode switch
       DEC  @LINF
 
WINDOW EQU  $
       LI   R8,WNLIN          Line number mode table
       ABS  @LINF             Line number mode?
       JEQ  WIND05            Yes
WINCMD LI   R8,WLIN           Other table
WIND05 LI   R7,WTOP           Top of window table
WIND10 LI   R9,3              3 table entries, each 4 bytes
WIND20 MOVB *R8+,@1(R7)       Put column # in right byte
       MOV  *R7+,*R7          Put column # in column end
       A    @SWIDTH,*R7+      Adjust for end of window
       DEC  R9
       JGT  WIND20
 
       SETO *R7               Set end of table flag
       LI   R7,WTOP           Restore pointer
       RT
 
*  Save/restore registers 1-7
*----------------------------
 
SAVEWS EQU  $
       LI   R9,SCNWS+2        Start at R1
       LI   R8,SREGS          Storage pointer
SAVE10 MOV  *R9+,*R8+         7 registers worth
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9+,*R8+
       MOV  *R9,*R8
       RT
 
*  Restore SCNWS registers
 
RESTWS EQU  $
REST10 LI   R9,SREGS          Storage pointer
       LI   R8,SCNWS+2        Restore from R1 on
       JMP  SAVE10
 
*  Purge Text buffer for new file
*--------------------------------
 
PURGE  EQU  $
       CLR  @SREGS2           Cursor to first column
       CLR  @PFLAG            Indicate cleared buffer
 
PURGF  EQU  $
       CLR  @MKTBL            Reset marker
       CLR  @MKSAV
       CLR  @CHNGED           Reset edited file indicator
       CLR  @EOFONS
       MOVB @AONE,@CRNTAB     Initialize TAB pointer
       LI   R1,TBL
       MOV  R1,@TBLND         Load R1 of BFMWS
       LI   R3,EDITBF
       MOV  R3,@EDBFND        Load R2 of BFMWS
       CLR  @EOF
       CLR  R1                Cline
       CLR  R3                Sbias                   Necessary? JJ
       RT
 
 
*-------------------------------------------------------------------
 
