## BASLOAD PETSCII UG CRLF
## PROGRAMMING BY STEFAN JAKOBSSON AND TOM TARDIS

FILENAME$="/X16EDITRC"
KEYCOL=22
KEYROW=18

GOSUB SETDEFAULTS

CLS
PRINT"********************************"
PRINT"X16 EDIT KEY BINDING CONFIG TOOL"
PRINT"********************************"
PRINT
PRINT"USAGE:"
PRINT
PRINT"CONTROL CHARACTERS OR BYTE VALUES MAY BE ENTERED IN THE FOLLOWING"
PRINT"TWO WAYS: (1) A PRINTABLE CHARACTER MAY BE ENTERED AS SUCH"
PRINT"(2) THE BYTE VALUE OF NON-PRINTABLE CHARACTERS MAY BE ENTERED IN DECIMAL"
PRINT"FORM WITH EXACTLY THREE DIGITS, FOR EXAMPLE 009 IS THE BYTE VALUE"
PRINT"OF THE TAB KEY."
PRINT
PRINT"CHARACTERS AND BYTE VALUES MUST MATCH THE VALUE RETURNED BY KERNAL"
PRINT"FUNCTION GETIN ($FFE4)."
PRINT
PRINT"PRESS ENTER TO KEEP THE CURRENT VALUE."
PRINT

REM **************************
REM GET USER DEFINED SHORTCUTS
REM **************************
SHOWKEYS:
  RESTORE
  LOCATE KEYROW,1
  FOR I=0 TO 25
      K$=""
      READ D$
      PRINT D$;TAB(KEYCOL);": ";
      COLOR 7
      IF K(I)>=64 AND K(I)<=90 THEN PRINT CHR$(K(I)):GOTO PL1
      COLOR 3
      PRINT CHR$(157);K(I)
      PL1:
      COLOR 1
  NEXT I

SHOW.MENU:
  PRINT
  INPUT "[�S]AVE [�E]DIT [�R]ESET [�Q]UIT";A$
  IF A$="R" THEN DELETE.CFG
  IF A$="E" THEN EDIT.KEYS
  IF A$="Q" THEN PRINT:PRINT "EXITING WITHOUT SAVE":END
  IF A$="S" THEN WRITE
GOTO SHOW.MENU

EDIT.KEYS:
  RESTORE
  LOCATE KEYROW,1
  FOR I=0 TO 25
      K$=""
      READ D$
      PRINT D$;TAB(KEYCOL);": ";
      COLOR 7
      LINPUT K$
      COLOR 1
      GOSUB PARSENUM
      IF K$<>"" THEN K(I)=ASC(K$)
  NEXT I
GOTO SHOW.MENU

WRITE:
  PRINT "SAVING TO ";FILENAME$
  OPEN 1,8,4,"@:"+FILENAME$+",S,W"
  FOR I=0 TO 25
    PRINT#1,CHR$(K(I));
  NEXT I
  CLOSE 1
  DOS
  PRINT "COMPLETE"
END

DELETE.CFG:
  DOS"S:/"+FILENAME$
GOTO SHOW.MENU

PARSENUM:
  V=VAL(K$)
  IF V=0 AND LEN(K$)>1 THEN PN.ERROR
  IF V=0 THEN PN.DONE
  IF V <1 OR V>255 THEN PN.ERROR
  K$=CHR$(V)
  GOTO PN.DONE
  
  PN.ERROR:
    LOCATE KEYROW+I,KEYCOL-5
    PRINT " ERROR"
    
  PN.DONE:
RETURN

REM *********************
REM SET DEFAULT SHORTCUTS
REM *********************

SETDEFAULTS:
  DIM K(25)
  K(0)=ASC("G")
  K(1)=ASC("X")
  K(2)=ASC("O")
  K(3)=ASC("R")
  K(4)=ASC("N")
  K(5)=ASC("J")
  K(6)=ASC("Y")
  K(7)=ASC("V")
  K(8)=ASC("K")
  K(9)=ASC("C")
  K(10)=ASC("U")
  K(11)=25
  K(12)=ASC("W")
  K(13)=ASC("S")
  K(14)=ASC("L")
  K(15)=ASC("A")
  K(16)=ASC("Z")
  K(17)=ASC("E")
  K(18)=ASC("I")
  K(19)=ASC("D")
  K(20)=ASC("T")
  K(21)=ASC("B")
  K(22)=ASC("M")
  K(23)=ASC("F")
  K(24)=13
  K(25)=ASC("Q")

  PRINT "READING ";FILENAME$
  PRINT
  OPEN 8,8,8,FILENAME$+",S,R"
  OPEN 15,8,15
  INPUT#15,A,A$
  IF A<>0 THEN NOFILE
  FOR I=0 TO 25
    GET#8,A$
    IF ST=64 THEN I=999:GOTO R1
    K(I)=ASC(A$)
    R1:
  NEXT
  GOTO SETDEF.DONE
  NOFILE:
  PRINT
  PRINT A;A$;
  PRINT ": USING DEFAULTS"
  PRINT "[PRESS RETURN]";
  LINPUT A$
  SETDEF.DONE:
  CLOSE 8
  CLOSE 15
RETURN

REM **************************
REM PROMPT STRINGS
REM **************************
DATA"GET HELP"
DATA"EXIT PROGRAM"
DATA"WRITE TO FILE"
DATA"READ FILE"
DATA"NEW BUFFER"
DATA"JUSTIFY BUFFER"
DATA"PAGE UP"
DATA"PAGE DOWN"
DATA"CUT LINE"
DATA"COPY LINE"
DATA"PASTE CLIPBOARD"
DATA"DELETE LINE"
DATA"SEARCH"
DATA"REPLACE"
DATA"GOTO LINE NUMBER"
DATA"AUTO INDENT"
DATA"WORD WRAP"
DATA"CHANGE CHARSET"
DATA"INVOKE DOS COMMAND"
DATA"SET DEVICE NUMBER"
DATA"CHANGE TEXT COLOR"
DATA"CHANGE BG COLOR"
DATA"SHOW MEMORY USAGE"
DATA"PRG TOOLBOX"
DATA"LINE BREAK ENCODING"
DATA"QUOTE MODE"
