;*************************** AMUS Program Label ******************************
; Filename: FUNKEY.M68                                      Date: 05/08/89
; Category: UTIL         Hash Code: 030-314-612-161      Version: 1.0
; Initials: ULTR/AM      Name: DAVID PALLMANN
; Company: ULTRASOFT                               Telephone #: 5163484848
; Related Files: NONE
; Min. Op. Sys.: NA                            Expertise Level: BEG
; Special: THIS IS NEW SOFTWARE, USE IT WITH CAUTION
; Description: Allows creation/modification of function key translation files
; Usage .FUNKEY       or      .FUNKEY filename
;
;*****************************************************************************

;****************************************************************************
;*                                                                          *
;*                                 FUNKEY                                   *
;*                 Function Key Translation Builder/Editor                  *
;*                                                                          *
;****************************************************************************
;Copyright (C) 1989 UltraSoft Corporation.  All Rights Reserved.
;
;Written by: David Pallmann
;
;Edit History:
;1.0(100)  05-May-89  created. /DFP

       VMAJOR  =1
       VMINOR  =0
       VSUB    =0
       VEDIT   =100.
       VWHO    =0

       SEARCH  SYS
       SEARCH  SYSSYM
       SEARCH  TRM

;variables

       .OFINI
       .OFDEF  FILE,   D.DDB           ; file DDB
       .OFDEF  TDVNAM, 8.              ; terminal driver name
       .OFDEF  EXTCHR, 1               ; exit character
       .OFSIZ  MEMSIZ

;macros

DEFINE  CURSOR  ROW,COL
       MOVB    ROW,D1
       ROLW    D1,#8.
       MOVB    COL,D1
       TCRT
       ENDM

DEFINE  CRT     N
       MOVW    #-1_8.+^D<N>,D1
       TCRT
       ENDM

START:  PHDR    -1,0,PH$REE!PH$REU      ; program header
       GETIMP  MEMSIZ,A5               ; allocate memory for variables
       INIT    FILE(A5)                ;
       CALL    GETTDV                  ; get terminal driver name

;command line checking
;
;       short way is .FUNKEY filespec
;
;       long way is .FUNKEY

CMDLIN: BYP                             ;
       LIN                             ;
       JEQ     LONG                    ;

;Name of translation file was entered on the command line.  Clearly, we are
;dealing with an experience data processing professional here.

SHORT:  FSPEC   FILE(A5),AMX            ;
       INIT    FILE(A5)                ;
       LOOKUP  FILE(A5)                ;
       BEQ     LOAD                    ;
       PFILE(A5)                       ;
       TYPE    < does not exist - create it? >
       KBD     EXIT                    ;
       CMPB    @A2,#'Y                 ;
       JNE     EXIT                    ;

;create a new translation file in memory

CREATE: USRFRE  A3                      ;
       MOV     A3,A4                   ;
       CLR     (A4)+                   ;
       MOV     #256.-1,D6              ;
10$:    MOVW    #1004,(A4)+             ;
       DBF     D6,10$                  ;
       JMP     READY                   ;

;load an existing translation file into memory

LOAD:   TYPESP  Loading                 ;
       PFILE   FILE(A5)                ;
       OPENI   FILE(A5)                ;
       USRFRE  A3                      ;
       MOV     A3,A4                   ;
10$:    FILINB  FILE(A5)                ;
       TST     FILE+D.SIZ(A5)          ;
       BEQ     20$                     ;
       MOVB    D1,(A4)+                ;
       BR      10$                     ;
20$:    CLOSE   FILE(A5)                ;
       JMP     READY                   ;

;user did not enter anything on the command line
;assume the worst - that the user has no prior experience with the subject
;matter at hand - and walk him through it.

LONG:   TYPESP  FUNKEY version          ;
       VCVT    START+2,OT$TRM          ;
       CRLF                            ;
       TYPECR  Copyright (C) 1989 UltraSoft Corporation.  All Rights Reserved.
       CRLF                            ;
       TYPESP  Do you need instructions on how to create a function key translation file?
       KBD     EXIT                    ;
       CRLF                            ;
       CMPB    @A2,#'Y                 ;
       BNE     GETNAM                  ;
       TTYL    HELP                    ;

;show the user the name of his terminal driver, and give him the option to
;override it

GETNAM: TYPESP  Your terminal driver name is
       TTYL    TDVNAM(A5)              ;
       TYPECR  .                       ;
       TYPESP  <Press RETURN to use this name, or enter alternate name now: >
       KBD     EXIT                    ;
       CRLF                            ;
       LIN                             ;
       BNE     10$                     ;
       LEA     A2,TDVNAM(A5)           ;
10$:    LEA     A1,FILE+D.FIL(A5)       ;
       PACK                            ;
       PACK                            ;

;option to show user the common translation file extensions

SHOEXT: TYPESP  Do you want to see a list of standard file extensions?
       KBD     EXIT                    ;
       CRLF                            ;
       CMPB    @A2,#'N                 ;
       BEQ     GETEXT                  ;
       CMPB    @A2,#'Y                 ;
       BNE     SHOEXT                  ;
       TTYL    STDEXT                  ;

;get the translation file extension

GETEXT: TYPESP  Enter translation type (three letter file extension):
       KBD     EXIT                    ;
       CRLF
       CMPB    @A2,#'.                 ;
       BNE     10$                     ;
       INC     A2                      ;
10$:    ALF                             ;
       BNE     GETEXT                  ;
       LEA     A1,FILE+D.EXT(A5)       ;
       PACK                            ;

;see if the translation file exists

LOOKUP: LOOKUP  FILE(A5)                ;
       JEQ     LOAD                    ;

;confirm the filename

NEWFIL: TYPESP  The file you wish to create will be named
       PFILE   FILE(A5)                ;
       TYPE    < - is this correct? >  ;
       KBD     EXIT                    ;
       CRLF                            ;
       CMPB    @A2,#'N                 ;
       BEQ     CRAP11                  ;
       CMPB    @A2,#'Y                 ;
       BNE     NEWFIL                  ;
       JMP     CREATE                  ;

CRAP11: JMP     GETNAM




;we are ready to get down to business
;put the terminal into single character mode
;clear the screen and echo the file specification

READY:  TRMRST  D0                      ;
       ORW     #T$DAT!T$ECS!T$XLT,D0   ;
       TRMWST  D0                      ;
       CRT     0                       ;
       TYPESP  Editing                 ;
       PFILE   FILE(A5)                ;
       CRLF                            ;
       CRLF                            ;

;get exit key

GTEXIT: TYPESP  Please enter the key that means "I'm done" with a definition:
       TIN                             ;
       MOVB    D1,EXTCHR(A5)           ;
       CALL    ECHO                    ;
       CRLF                            ;
       CRLF                            ;

;get key to translate

GETKEY: CURSOR  #5,#1                   ;
       TYPESP  Press the key you want to translate:
       CRT     10                      ;
       TIN                             ;
       CMPB    D1,EXTCHR(A5)           ;
       BEQ     DONE                    ;
       CALL    ECHO                    ;
       CRLF                            ;
       CRLF                            ;
       MOV     A3,A0                   ;
       ADD     #4,A0                   ;
       ADD     D1,A0                   ;
       ADD     D1,A0                   ;
       MOV     A4,D0                   ;
       SUB     A3,D0                   ;
       CLR     D2                      ;
       MOVW    @A0,D2                  ;
       CALL    CURENT                  ;
       MOVW    D0,@A0                  ;

;prompt for translation definition

GETDEF: TYPESP  Enter the character(s) that
       CALL    ECHO                    ;
       TYPECR  < should translate to:> ;
       CRLF                            ;

;get character of replacement text

GETCHR: TIN                             ;
       CMPB    D1,EXTCHR(A5)           ;
       BEQ     10$                     ;
       MOVB    D1,(A4)+                ;
       CALL    ECHO                    ;
       BR      GETCHR                  ;
10$:    CLRB    (A4)+                   ;
       JMP     GETKEY                  ;

;done with translation
;mark end of translation string with a null

DONE:   TRMRST  D0                      ;
       ANDW    #^C<T$DAT!T$ECS!T$XLT>,D0
       TRMWST  D0                      ;
       CRLF                            ;
       CRLF                            ;

;confirm update of file

CONFIRM:
       TYPESP  Okay to update          ;
       PFILE   FILE(A5)                ;
       TYPE    < with these changes? > ;
       KBD     EXIT                    ;
       CRLF                            ;
       CMPB    @A2,#'N                 ;
       JEQ     FINISH                  ;
       CMPB    @A2,#'Y                 ;
       BNE     CONFIRM                 ;

;update the translation file on disk

UPDATE: CRLF                            ;
       TYPESP  Updating                ;
       PFILE   FILE(A5)                ;
       CRLF                            ;
       LOOKUP  FILE(A5)                ;
       BNE     10$                     ;
       DSKDEL  FILE(A5)                ;
10$:    OPENO   FILE(A5)                ;
20$:    CMP     A3,A4                   ;
       BHIS    30$                     ;
       MOVB    (A3)+,D1                ;
       FILOTB  FILE(A5)                ;
       BR      20$                     ;
30$:    CLOSE   FILE(A5)                ;

;all done

FINISH: CURSOR  #23.,#1                 ;

EXIT:   EXIT

;************
;*  GETTDV  *
;************
;Function:      get terminal driver name
;
;Inputs:        none
;
;Outputs:       TDVNAM(A5) - ASCIZ representation of terminal driver name

GETTDV: SAVE    A0-A2                   ;
       JOBIDX  A0                      ;
       MOV     JOBTRM(A0),A1           ;
       MOV     T.TDV(A1),A1            ;
       SUB     #4,A1                   ;
       LEA     A2,TDVNAM(A5)           ;
       UNPACK                          ;
       UNPACK                          ;
10$:    CMPB    -(A2),#40               ;
       BEQ     10$                     ;
       CLRB    1(A2)                   ;
       REST    A0-A2                   ;
       RTN                             ;

;**********
;*  ECHO  *
;**********
;Function:      Echo character
;
;Inputs:        D1 - character to echo

ECHO:   SAVE    D1                      ;
       CMPB    D1,#11                  ;
       BEQ     EC.TAB                  ;
       CMPB    D1,#15                  ;
       BEQ     EC.RET                  ;
       CMPB    D1,#40                  ;
       BLO     EC.CTL                  ;
       CMPB    D1,#177                 ;
       BEQ     EC.DEL                  ;
       BHI     EC.NUM                  ;
EC.CHR: TTY                             ;
       BR      EC.RTN                  ;
EC.TAB: TYPE    {TAB}                   ;
       BR      EC.RTN                  ;
EC.RET: TYPECR  {RETURN}                ;
       BR      EC.RTN                  ;
EC.CTL: TYPE    ^                       ;
       ADDB    #'@,D1                  ;
       TTY                             ;
       BR      EC.RTN                  ;
EC.DEL: TYPE    {RUBOUT}                ;
       BR      EC.RTN                  ;
EC.NUM: TYPE    {                       ;
       AND     #377,D1                 ;
       DCVT    0,OT$TRM                ;
       TYPE    }                       ;
EC.RTN: REST    D1                      ;
       RTN                             ;

;************
;*  CURENT  *
;************
;Function:      Show current translation
;
;Inputs:        D2 - vector (zero means no translation)
;               A3 - base of translation module in memory

CURENT: SAVE    A0,D1                   ;
       TSTW    D2                      ;
       BEQ     90$                     ;
       MOV     A3,A0                   ;
       ADDW    D2,A0                   ;
       TSTB    @A0                     ;
       BEQ     90$                     ;
       TYPESP  Current translation:    ;
10$:    MOVB    (A0)+,D1                ;
       BEQ     20$                     ;
       CALL    ECHO                    ;
       BR      10$                     ;
20$:    CRLF                            ;
       CRLF                            ;
90$:    REST    A0,D1                   ;
       RTN                             ;

DEFINE  LINE    TEXT
       ASCII   "TEXT"
       BYTE    15
       ENDM

HELP:   LINE    <Not all keyboards are the same.  Terminals from various manufacturers often>
       LINE    <differ in the number and kind of function keys available.  The program>
       LINE    <you are running can be used to create or modify a translation file that>
       LINE    <associates meanings to function keys.>
       LINE
       LINE    <By function keys, we are referring to both the numbered 'F' keys (F1, F2, F3,>
       LINE    <and so forth) as well as the 'special' keys (DEL CHAR, EXECUTE, NEXT SCREEN,>
       LINE    <etc.).  The only keys that do NOT require special translation are the>
       LINE    <common ones: A-Z, a-z, 0-9, !@#$%^&*()-_=+`~\|]}[{;:'/?., SPACE BAR,>
       LINE    <RETURN, TAB, ENTER, and HOME.  Anything else on your keyboard probably does>
       LINE    <need translation.>
       LINE
       BYTE    0

STDEXT: LINE    <       ABX  AlphaBASE>                 MAX   AlphaMAIL>
       LINE    <       AMX  Alpha Micro line editor    MLX   MULTI>
       LINE    <       CAX  AlphaCALC                  USX   UltraSoft>
       LINE    <       FIX  AlphaFIX                   VUX   AlphaVUE>
       LINE    <       IFX  INFLD.SBR                  WRT   AlphaWRITE>
       LINE    <       IMX  INMEMO.SBR>
       LINE
       BYTE    0
       EVEN

       END