Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / usb-devices / kbd / kbdutils.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: kbdutils.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)kbdutils.fth 1.36 98/01/22
43purpose: Converts Sun keyboard events to ASCII characters
44copyright: Copyright 1990-2000 Sun Microsystems, Inc. All Rights Reserved
45
46\
47\ The USB keyboard sends "down" keycodes (key #s) which are immediately
48\ converted into ASCII characters (keyvalues) and enqueued. The keycodes
49\ are extracted from USB "interrupt" reports (meaning that the device is
50\ polled periodically) which is initiated by the poll-usb word.
51\ poll-usb also checks for "abort" ("Stop" key and "a" key down
52\ simultaneously). When a program wants a character from the keyboard
53\ it calls getkey. getkey merely removes a keyvalue from the queue
54\ and returns it, or -1 if the queue is empty.
55
56
57: time-reached? ( when -- flag ) get-msecs - 0< ;
58
59
60\ headerless \ XXX keep heads for debugging
61external
62
63\ Keyboard-specific information
64h# de constant kb-unknown \ Random unlikely to be seen
65\ d# 120 constant Abortkey1 \ First key of abort seq - L1 (USB)
66\ d# 4 constant Abortkey2 \ Second key of abort seq - "a" (USB)
67
68
69\ Keymaps
70\ 0 constant K-Normalmap
71\ 1 constant K-Shiftmap
72\ 2 constant K-Altgmap
73
74\ headers \ XXX for debugging
75\ Returns a keyboard keyvalue (an ascii value which was obtained from
76\ the keycode which was returned by the USB report). First check for a
77\ key arriving from USB, if no key then check to see if there may already
78\ be one in the queue. Implement auto-repeat if the same key hass been
79\ down for the specified length of time. If there are no keys available
80\ then -1 is returned.
81\
82\ headers \ XXX for debugging
83external
84: getkey ( -- keyvalue )
85 mutex-enter if
86 nokey exit ( no-key )
87 then
88
89 poll-usb if
90 \ Got a Stop-A.
91 clear-keyboard nokey
92 mutex-exit user-abort ( no-key )
93 then
94
95 keybuf-empty? if ( )
96 \ There were no new keys enqueued, check to see if we should return
97 \ the repeat key.
98 curr-repeat-key if ( )
99 key-repeat-time time-reached? ( flag )
100 else
101 false
102 then
103
104 if \ Repeating?
105 \ Yes, we have a repeat key and the repeat timer has expired.
106 get-msecs d# 52 + to key-repeat-time
107 \ Reinit the timer for next time around.
108 curr-repeat-key ( keycode-repeat )
109 else
110 nokey ( no-key-dn )
111 then
112 else
113 \ Queue is not empty - get a char.
114 bget ( new-keyvalue )
115 then
116 mutex-exit exit ( keyvalue )
117;
118
119: read-bytes ( addr len -- #bytes-read )
120 dup 0= if \ check for possible 0 len read
121 nip exit
122 then
123
124 0 begin ( addr' len #bytes-read' )
125 getkey ( addr' len #bytes-read' byte|-1 )
126 dup -1 = if ( addr' len #bytes-read' byte|-1 )
127 2swap 2drop ( #bytes-read until-flag )
128 else \ write the byte, incr addr, incr count, check for max len
129 3 pick c! ( addr' len #bytes-read' ) \ write the byte
130 1+ 2dup = if ( addr' len #bytes-read' ) \ incr cnt, chk for max
131 nip nip true ( #bytes-read until-flag )
132 else ( addr' len #bytes-read' )
133 rot 1+ -rot ( addr' len #bytes-read' ) \ incr addr
134 false ( addr' len #bytes-read' until-flag )
135 then
136 then
137 until ( #bytes-read )
138;
139
140\ headerless \ XXX keep heads for debugging