The Pedigree Project  0.1
ppc_common/Keyboard.cc
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "Keyboard.h"
21 
22 PPCKeyboard::PPCKeyboard() : m_Dev(0)
23 {
24 }
25 
26 PPCKeyboard::~PPCKeyboard()
27 {
28 }
29 
31 {
32  // m_Dev = OFDevice(OpenFirmware::instance().findDevice("/keyboard"));
33  OFDevice chosen(OpenFirmware::instance().findDevice("/chosen"));
34  m_Dev = chosen.getProperty("stdin");
35  // for(;;);
36 }
37 
39 {
40  // if (m_bDebugState)
41  //{
42  char c[4];
43  while (OpenFirmware::instance().call(
44  "read", 3, m_Dev, reinterpret_cast<OFParam>(c),
45  reinterpret_cast<OFParam>(4)) != 0)
46  ;
47  if ((c[0] < ' ' || c[0] > '~') && c[0] != '\r' && c[0] != 0x08 &&
48  c[0] != 0x09)
49  return 0;
50  else
51  return c[0];
52  //}
53  // else
54  // {
55  // FATAL("KEYBOARD: getChar() should not be called in normal mode!");
56  // return 0;
57  // }
58 }
59 
61 {
62  // if (m_bDebugState)
63  //{
64  char c[4];
65  if (OpenFirmware::instance().call(
66  "read", 3, m_Dev, reinterpret_cast<OFParam>(c),
67  reinterpret_cast<OFParam>(4)) != 0)
68  return 0;
69  if ((c[0] < ' ' || c[0] > '~') && c[0] != '\r' && c[0] != 0x08 &&
70  c[0] != 0x09)
71  return 0;
72  if (c[0] == '\r')
73  return '\n';
74  else
75  return c[0];
76  //}
77  // else
78  //{
79  // FATAL("KEYBOARD: getCharNonBlock() should not be called in normal
80  // mode!"); return 0;
81  // }
82 }
83 
84 Keyboard::Character PPCKeyboard::getCharacter()
85 {
86  Character c;
87  c.valid = 1;
88  c.ctrl = c.alt = c.shift = c.caps_lock = 0;
89  c.num_lock = c.is_special = c.reserved = 0;
90  c.value = getChar();
91 
92  return c;
93 }
94 
95 Keyboard::Character PPCKeyboard::getCharacterNonBlock()
96 {
97  Character c;
98  c.valid = 1;
99  c.ctrl = c.alt = c.shift = c.caps_lock = 0;
100  c.num_lock = c.is_special = c.reserved = 0;
101  c.value = getCharNonBlock();
102 
103  return c;
104 }
105 
106 void PPCKeyboard::setDebugState(bool enableDebugMode)
107 {
108 }
virtual char getCharNonBlock()
virtual char getChar()
static OpenFirmware & instance()
Definition: OpenFirmware.h:45
virtual char getChar()
virtual char getCharNonBlock()
virtual Character getCharacterNonBlock()
virtual void initialise()
virtual void setDebugState(bool enableDebugMode)
virtual Character getCharacter()