Annotation of gforth/dosekey.fs, revision 1.3

1.1       pazsan      1: \ dosekey, based on:
                      2: \ ekey etc.
                      3: 
1.3     ! anton       4: \ Copyright (C) 2001,2007 Free Software Foundation, Inc.
1.1       pazsan      5: 
                      6: \ This file is part of Gforth.
                      7: 
                      8: \ Gforth is free software; you can redistribute it and/or
                      9: \ modify it under the terms of the GNU General Public License
1.2       anton      10: \ as published by the Free Software Foundation, either version 3
1.1       pazsan     11: \ of the License, or (at your option) any later version.
                     12: 
                     13: \ This program is distributed in the hope that it will be useful,
                     14: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
                     15: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     16: \ GNU General Public License for more details.
                     17: 
                     18: \ You should have received a copy of the GNU General Public License
1.2       anton      19: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1       pazsan     20: 
                     21: 
                     22: \ this implementation of EKEY just translates the KEY values
                     23: \ received following a null to values between 256 and 511
                     24: 
                     25: \ Caveats: It also translates a sequence of two codes beginning with
                     26: \ 0 if they were not generated by pressing the key.  It does not wait
                     27: \ for the second value in the sequence to arrive.
                     28: 
                     29: \ In a Forth implementation on DOS in which special keys are not 
                     30: \ available by a second call to KEY following a null value, this
                     31: \ code will not work.  It has only been used on Gforth 0.5
                     32: 
                     33: \ The dos-keycode names are compatible with pfe-0.9.14
                     34: 
                     35: : dos-keycode ( c "name" -- ; name execution: -- u ) 256 + constant ;
                     36: 
                     37: 75 dos-keycode k-left
                     38: 77 dos-keycode k-right
                     39: 72 dos-keycode k-up
                     40: 80 dos-keycode k-down
                     41: 71 dos-keycode k-home
                     42: 79 dos-keycode k-end
                     43: 115 keycode k-prior \ note: captured by xterm
                     44: 116 keycode k-next \ note: captured by xterm
                     45: 82 dos-keycode k-insert \ not in pfe
                     46: \ function/keypad keys
                     47: 59 dos-keycode k1
                     48: 60 dos-keycode k2
                     49: 61 dos-keycode k3
                     50: 62 dos-keycode k4
                     51: 63 dos-keycode k5
                     52: 64 dos-keycode k6
                     53: 65 dos-keycode k7
                     54: 66 dos-keycode k8
                     55: 67 dos-keycode k9
                     56: 68 dos-keycode k10
                     57: 133 dos-keycode k11 \ not in pfe
                     58: 134 dos-keycode k12 \ not in pfe
                     59: 
                     60: \ shifted function/keypad keys have the same key sequences (in
                     61: \ xterm) and pfe gives the same keycodes; so use of these is
                     62: \ not portable to gforth outside of DOS
                     63: 84 dos-keycode s-k1
                     64: 85 dos-keycode s-k2
                     65: 86 dos-keycode s-k3
                     66: 87 dos-keycode s-k4
                     67: 88 dos-keycode s-k5
                     68: 89 dos-keycode s-k6
                     69: 90 dos-keycode s-k7
                     70: 91 dos-keycode s-k8
                     71: 92 dos-keycode s-k9
                     72: 93 dos-keycode s-k10
                     73: 135 dos-keycode s-k11 \ not in pfe
                     74: 136 dos-keycode s-k12 \ not in pfe
                     75: 
                     76: : ekey ( -- u ) \ facility-ext e-key
                     77:     key ?dup 0= if key 256 + then
                     78: ;
                     79: 
                     80: : ekey>char ( u -- u false | c true ) \ facility-ext e-key-to-char
                     81:     dup 256 u<
                     82: ;
                     83: 
                     84: : ekey? ( -- flag ) \ facility-ext e-key-question
                     85:     \G Return @code{true} if a keyboard event is available (use
                     86:     \G @code{ekey} to receive the event), @code{false} otherwise.
                     87:     key?
                     88: ;
                     89: 
                     90: FALSE [IF]
                     91:    : test-ekey?
                     92:       begin
                     93:          begin
                     94:             begin key? until
                     95:          ekey? until
                     96:          .s ekey .s drop
                     97:       again
                     98:    ;
                     99:    test-ekey?
                    100: [THEN]

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>