;; Map atari st function key escape sequences
;; into the standard slots in function-keymap.

(require 'keypad)

(defvar st-map nil
  "The st-map maps the function keys on the atari keyboard.")

(if (not st-map)
    (progn
     (setq st-map (lookup-key esc-map "*"))
     (if (not (keymapp st-map))
	 (setq st-map (make-sparse-keymap)))  ;; <ESC>* commands
     (setup-terminal-keymap st-map
	    '(("H" . ?u)		; up arrow
	      ("P" . ?d)		; down-arrow
	      ("M" . ?r)		; right-arrow
	      ("K" . ?l)		; left-arrow
	      ("G" . ?h)		; Home
	      ("b" . ??)		; Help
	      ("-" . ?-)		; keypad -
	      ("." . ?.)		; keypad .
	      ("0" . ?0)		; 0
	      ("1" . ?1)		; 1
	      ("2" . ?2)		; 2
	      ("3" . ?3)		; 3
	      ("4" . ?4)		; 4
	      ("5" . ?5)		; 5
	      ("6" . ?6)		; 6
	      ("7" . ?7)		; 7
	      ("8" . ?8)		; 8
	      ("9" . ?9)		; 9
	      (";" . ?\C-a)              ; F1
	      ("<" . ?\C-b)
	      ("=" . ?\C-c)
	      (">" . ?\C-d)
	      ("??" . ?\C-e)
	      ("@" . ?\C-f)
	      ("A" . ?\C-g)
	      ("B" . ?\C-h)
	      ("C" . ?\C-i)
	      ("D" . ?\C-j)
	      ("T" . ?\C-k)
	      ("U" . ?\C-l)
	      ("V" . ?\C-m)
	      ("W" . ?\C-n)
	      ("X" . ?\C-o)
	      ("Y" . ?\C-p)
	      ("Z" . ?\C-q)
	      ("[" . ?\C-r)
	      ("\\" . ?\C-s)
	      ("]" . ?\C-t)
	      ("\C-r" . ?A)		; C-Insert -> insert line key
	      ("R" . ?I)		; Insert
	      ("\C-p" . ?N)             ; C-downarrow -> next page key
	      ("\C-h" . ?P)		; C-uparrow -> previous page key
              ("a" . ?U)))		; Undo

     (define-key esc-map "*" st-map)))

