1
\ *****************************************************************************
2
\ * Copyright (c) 2004, 2008 IBM Corporation
3
\ * All rights reserved.
4
\ * This program and the accompanying materials
5
\ * are made available under the terms of the BSD License
6
\ * which accompanies this distribution, and is available at
7
\ * http://www.opensource.org/licenses/bsd-license.php
10
\ * IBM Corporation - initial implementation
11
\ ****************************************************************************/
14
: input ( dev-str dev-len -- )
17
s" stdin" get-chosen IF
18
decode-int nip nip ?dup IF close-dev THEN
20
\ Now set the new stdin:
21
encode-int s" stdin" set-chosen
25
: output ( dev-str dev-len -- )
28
s" stdout" get-chosen IF
29
decode-int nip nip ?dup IF close-dev THEN
31
\ Now set the new stdout:
32
encode-int s" stdout" set-chosen
36
: io ( dev-str dev-len -- )
41
1 BUFFER: (term-io-char-buf)
43
: term-io-key ( -- char )
44
s" stdin" get-chosen IF
45
decode-int nip nip dup 0= IF 0 EXIT THEN
47
(term-io-char-buf) 1 s" read" r@ $call-method
53
[ ' key behavior compile, ]
59
\ this word will check what the current chosen input device is:
60
\ - if it is a serial device, it will use serial-key? to check for available input
61
\ - if it is a keyboard, it will check if the "key-available?" method is implemented (i.e. for usb-keyboard) and use that
62
\ - if it's an hv console, use hvterm-key?
63
\ otherwise it will always return false
64
: term-io-key? ( -- true|false )
65
s" stdin" get-chosen IF
66
decode-int nip nip dup 0= IF drop 0 EXIT THEN \ return false and exit if no stdin set
67
>r \ store ihandle on return stack
68
s" device_type" r@ ihandle>phandle ( propstr len phandle )
69
get-property ( true | data dlen false )
71
\ device_type not found, return false and exit
74
1 - \ remove 1 from length to ignore null-termination char
75
\ device_type found, check wether it is serial or keyboard
76
2dup s" serial" str= IF
77
2drop serial-key? r> drop EXIT
78
THEN \ call serial-key, cleanup return-stack, exit
79
2dup s" keyboard" str= IF
81
\ keyboard found, check for key-available? method, execute it or return false
82
s" key-available?" r@ ihandle>phandle find-method IF
83
drop s" key-available?" r@ $call-method
87
r> drop EXIT \ cleanup return-stack, exit
89
2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
92
\ stdin not set, return false
97
' term-io-key? to key?