'===========================================================================
' Subject: ASIC EXTENDED FUNCTION DEMO        Date: 03-26-98 (15:58)       
'  Author: John A. Kiernan                    Code: ASIC                   
'  Origin: jkiernan@julian.uwo.ca           Packet: ASIC.ABC
'===========================================================================
rem  EXTEND.ASI    Demonstrating ASIC's system variable EXTENDED
rem                by J. A. Kiernan, London, Canada. March 1998.

rem  This demonstrates responding to directional navigation (arrow) keys
rem  (and also to Delete, BackSpace, Enter and Escape).
rem  If the EXTENDED variable (generated by INKEY$) is not
rem  allowed for, the directional keys cannot be distinguished
rem  from certain capital letters (G,H,I,K,M,O,P,Q)
rem    Compilation:  ASICC EXTEND  (makes EXTEND.COM, 1544 bytes)
rem      This could also be made into a SUB and compiled as an .OBJ
rem      for calling by other ASIC programmes. To make a SUB, the VERY
rem      FIRST LINE of this file must be in the form:
rem                                          SUB "Extend" Key$,Line,Col
rem      and you must compile with the B/OBJ option.
rem      See also at the end of this file, for how to end a SUB in ASIC.
    COLOR 14,0
    CLS
    LOCATE 0,1
    PRINT "Use of Arrow keys and BackSpace with ASIC 5.0.          Press ";
    COLOR 0,7
    PRINT " Esc ";
    COLOR 14,0
    PRINT " to quit."
    COLOR 7,0
    Line=12
    Col=40
    GOSUB MakeMove:
 Wait:
    Key$=INKEY$
      IF Key$="" THEN Wait:
      IF EXTENDED=1 THEN
      rem                         Test for Up, Down, Left & Right arrows
      rem                         and move cursor appropriately
          IF Key$="H" THEN
          rem                    Up
            Line=Line-1
            GOSUB MakeMove:
          ENDIF
          IF Key$="P" THEN
          rem                    Down
            Line=Line+1
            GOSUB MakeMove:
          ENDIF
          IF Key$="K" THEN
          rem                    Left
            Col=Col-1
            GOSUB MakeMove:
          ENDIF
        rem
          IF Key$="M" THEN
          rem                    Right
            Col=Col+1
            GOSUB MakeMove:
          ENDIF
    rem                          Test for diagonal movement keys
    rem                          and position cursor accordingly
          IF Key$="G" THEN
          rem                    Home (Up and Left)
            Line=Line-1
            Col=Col-1
            GOSUB MakeMove:
          ENDIF
          IF Key$="I" THEN
          rem                    PgUp (Up and Right)
            Line=Line-1
            Col=Col+1
            GOSUB MakeMove:
          ENDIF
          IF Key$="O" THEN
          rem                    End (Down and Left)
            Line=Line+1
            Col=Col-1
            GOSUB MakeMove:
          ENDIF
          IF Key$="Q" THEN
          rem                    PgDn (Down and Right)
            Line=Line+1
            Col=Col+1
            GOSUB MakeMove:
          ENDIF
          IF Key$="S" THEN
          rem                     (Delete key. Print a space. Move to R.)
            PRINT " ";
            Col=Col+1
            GOSUB MakeMove:
          ENDIF
        GOTO Wait:
      ELSE
      rem                         (If EXTENDED=0, display character or quit)
        Key=ASC(Key$)
          IF Key=27 THEN TheEnd:
          rem                     (Esc=27. Breaks out of loops)
          IF Key=8 THEN
          rem                     (BackSpace=8. Go 1 left and print a space)
            Col=Col-1
            GOSUB MakeMove:
            PRINT " ";
            GOSUB MakeMove:
            GOTO Wait:
          ENDIF
          IF Key=13 THEN
          rem                     (Enter key = 13. Go to start of next line.)
            Line=Line+1
            Col=0
            GOSUB MakeMove:
            GOTO Wait:
          ENDIF
        PRINT Key$;
        rem           (Other keys: Print char, move to R., get new position.)
        Col=Col+1
        GOSUB MakeMove:
        GOTO Wait:
      ENDIF
    TheEnd:
rem  GOTO EndOfSub:  Replace the "END" command with this line
rem                  if you are compiling to make an .OBJ file
rem                  for a CALL SUB in other ASIC programmes.
      END

MakeMove:
rem       Subroutine to reposition cursor and allocate
rem       Line and Col to their new position(s).
rem          First prevent the cursor moving off the screen.
     IF Line<0 THEN
       Line=0
     ENDIF
     IF Line>24 THEN
       Line=24
     ENDIF
     IF Col<0 THEN
       Col=0
     ENDIF
     IF Col>79 THEN
       Col=79
     ENDIF
   LOCATE Line,Col
   Line=CSRLIN
   Col=POS(0)
   RETURN

rem EndOfSub:  Put this label here if you are compiling as a SUB
rem    An ENDSUB line like the one below is needed if you are compiling
rem    as a SUB, to make an .OBJ for use with CALL SUB in other programmes.
rem ENDSUB "Exten" Key$,Line,Col
