The get-key-map word is used by Bootx to determine which key is being held down at startup time. Since the Command key can't be detected in QEMU, the Control key is used instead. If the user holds down Control-v while Mac OS X starts up in QEMU, get-key-map will report that Command-v is being held down. Allowing the user to have Mac OS X to boot up in Verbose mode.
I was able to verify that this word works when I tested it out in the file forth.c, but I don't know how to access this word here in the adb_kbd.c file. Comments, suggestions, and commits are always welcomed.
--- drivers/adb_kbd.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/drivers/adb_kbd.c b/drivers/adb_kbd.c index e38798a..82382d5 100644 --- a/drivers/adb_kbd.c +++ b/drivers/adb_kbd.c @@ -42,11 +42,13 @@ keyboard_close(int *idx) }
static void keyboard_read(void); +void getKeyMap(void);
NODE_METHODS( keyboard ) = { - { "open", keyboard_open }, - { "close", keyboard_close }, - { "read", keyboard_read }, + { "open", keyboard_open }, + { "close", keyboard_close }, + { "read", keyboard_read }, + { "get-key-map", getKeyMap }, };
/* VT100 escape sequences */ @@ -566,3 +568,75 @@ static void keyboard_read(void) } PUSH(i); } + + +// Returns the base to the exponent power +static int pow(int base, int exponent) +{ + int index, answer; + answer = base; + for(index = 1; index < exponent; index++) + { + answer = answer * base; + } + return answer; +} + +// The implementation of the get-key-map word. +// Returns an array of 32 bytes. Certain bits +// are used to determine which keys are being +// held down. + +void getKeyMap(void) +{ + int keyPushed, *keyMapArray, offset; + const int sizeOfArray = 8; + const int modifierKeyIndex = 7; + const int commandKeyValue = pow(2,28); + const int shiftKeyValue = pow(2,30); + const int theAKeyValue = pow(2,27); + + keyMapArray = (char *) malloc(sizeOfArray); + if(!keyMapArray) + { + printk("Failed to allocate memory for keyMapArray!\n"); + PUSH(NULL); + return; + } + + // Set all the elements to zero + int index; + for(index = 0; index < sizeOfArray; index++) + { + keyMapArray[index] = 0; + } + + feval("key?"); + if(POP() != -1) // if no key was pushed + PUSH(keyMapArray); // returns the address of keyMapArray + + feval("key"); + keyPushed = POP(); + + if(keyPushed > 0 && keyPushed < 27) // control key combination + { + offset = 1; + keyMapArray[modifierKeyIndex] = commandKeyValue; + } + + else if(keyPushed > 64 && keyPushed < 91) // shift key combination + { + offset = 65; + keyMapArray[modifierKeyIndex] = shiftKeyValue; + } + + else // just a letter is being held down + { + offset = 97; + } + + // Determines the value and location of a bit in the array. + *keyMapArray = theAKeyValue >> (keyPushed - offset); + + PUSH(keyMapArray); +} \ No newline at end of file