This source file includes following definitions.
- keyPressed
- ProcessMsgQueue
- kbTaskCode
#include "memory.h"
#include "kernel.h"
#define KBDINT 1
#define GETCHAR 1
#define KEYPRESS 2
#define GETKEY 3
#define LSHIFT 42
#define RSHIFT 54
#define ALT 56
#define CTRL 29
#define CAPSLOCK 58
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define SHIFTED 1
#define LOCKED 2
#define CTRLED 4
#define ALTED 8
extern void switchConsole(long console);
long kbBufStart;
long kbBufCurrent;
unsigned char kbBufCount;
unsigned char kbBuffer[128];
unsigned char currentBuffer;
struct Console consoles[8];
char KbdTableU[] =
{ 0, 0 , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',
8 , 0 , 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
'o', 'p', '[', ']', 13, 0 , 'a', 's', 'd', 'f', 'g', 'h', 'j',
'k', 'l', ';', '\'', '`', 0 , '#', 'z', 'x', 'c', 'v', 'b',
'n', 'm', ',', '.', '/', 0 , 0 , 0 , ' ',
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 21 , 0 ,
0 , 12 , 0 , 18 ,
0 , 0 , 4 , 0 , 0 ,
0 , 0, 0, '\\', 0 , 0
};
char KbdTableS[] =
{ 0, 0 , '!', '"', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
8 , 0 , 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
'O', 'P', '{', '}', 13, 0 , 'A', 'S', 'D', 'F', 'G', 'H', 'J',
'K', 'L', ':', '@', '`', 0 , '#', 'Z', 'X', 'C', 'V', 'B',
'N', 'M', '<', '>', '?', 0 , 0 , 0 , ' ',
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 ,
'-' , 0 , '5' , 0 ,
'+' , 0 , 0 , 0 , 0 ,
0 , 0, 0, '|', 0 , 0
};
char KbdTableC[] =
{ 0, 0 , '!', '"', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',
8 , 0 , 17, 23, 5, 18, 20, 25, 21, 9, 15, 16, '{',
'}', 13, 0 , 1, 19, 4, 6, 7, 8, 10, 11, 12, ':', '@', '`',
0 , '#', 26, 24, 3, 22, 2, 14, 13, '<', '>', '?',
0 , 0 , 0 , ' ', 0 ,
0 , 0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 , 0 ,
0 , 0 , 0 , 0 ,
'-' , 0 , '5' , 0 ,
'+' , 0 , 0 , 0 , 0 ,
0 , 0, 0, '|', 0 , 0
};
void keyPressed()
{
struct Message *kbdMsg = (struct Message *) ALLOCMSG;
kbdMsg->nextMessage = 0;
kbdMsg->byte = KEYPRESS;
SendMessage((struct MessagePort *) KbdPort, kbdMsg);
DeallocMem(kbdMsg);
}
void ProcessMsgQueue(struct Console *console)
{
while (console->kbBufCount && console->MsgQueue)
{
unsigned char temp = console->kbBuffer[console->kbBufStart];
console->kbBufCount--;
console->kbBufStart++;
struct Message *tempMsg = console->MsgQueue;
console->MsgQueue = tempMsg->nextMessage;
if (tempMsg->byte == GETCHAR)
{
struct MessagePort *tempPort =
(struct MessagePort *) tempMsg->tempPort;
tempMsg->nextMessage = 0;
tempMsg->quad = 0L;
tempMsg->byte = temp;
SendMessage(tempPort, tempMsg);
}
DeallocMem(tempMsg);
}
}
void kbTaskCode()
{
kprintf(1, 0, "Starting Keyboard Task");
unsigned char temp = 0;
unsigned char modifier = 0;
struct MessagePort *tempPort;
struct Message *KbdMsg;
struct Console *currentCons;
struct Message *tempMsg;
int i;
for (i = 0; i < 4; i++)
{
consoles[i].kbBuffer = AllocUMem(128);
consoles[i].kbBufStart = consoles[i].kbBufCurrent =
consoles[i].kbBufCount = 0;
consoles[i].MsgQueue = 0;
}
kbBufStart = 0;
kbBufCurrent = 0;
kbBufCount = 0;
currentBuffer = 0;
asm("mov $0b11111000, %al");
asm("out %al, $0x21");
((struct MessagePort *) KbdPort)->waitingProc = (struct Task *) -1L;
((struct MessagePort *) KbdPort)->msgQueue = 0;
while (1)
{
KbdMsg = (struct Message *) ALLOCMSG;
ReceiveMessage((struct MessagePort *) KbdPort, KbdMsg);
switch (KbdMsg->byte)
{
case GETCHAR:
currentCons = &consoles[KbdMsg->quad];
tempMsg = currentCons->MsgQueue;
if (!tempMsg)
currentCons->MsgQueue = KbdMsg;
else
{
while (tempMsg->nextMessage)
tempMsg = tempMsg->nextMessage;
tempMsg->nextMessage = KbdMsg;
}
break;
case KEYPRESS:
currentCons = &(consoles[currentBuffer]);
while (kbBufCount)
{
temp = kbBuffer[kbBufStart];
kbBufCount--;
kbBufStart++;
if ((kbBufStart) == 128)
(kbBufStart) = 0;
if (temp < 0x80)
{
switch (temp)
{
case LSHIFT:
case RSHIFT:
modifier += SHIFTED;
break;
case CAPSLOCK:
if (modifier & LOCKED)
modifier -= LOCKED;
else
modifier += LOCKED;
break;
case CTRL:
modifier += CTRLED;
break;
case F1:
switchConsole(0);
break;
case F2:
switchConsole(1);
break;
case F3:
switchConsole(2);
break;
case F4:
switchConsole(3);
break;
default:
if (modifier & CTRLED)
temp = KbdTableC[temp];
else if (modifier & SHIFTED)
temp = KbdTableS[temp];
else
temp = KbdTableU[temp];
if (modifier & LOCKED)
{
if ((temp >= 'A') && (temp <= 'Z'))
temp += 0x20;
else if ((temp >= 'a') && (temp <= 'z'))
temp -= 0x20;
}
currentCons->kbBuffer[currentCons->kbBufCurrent] = temp;
currentCons->kbBufCount++;
currentCons->kbBufCurrent++;
break;
}
}
else
{
switch (temp & 0x7F)
{
case LSHIFT:
case RSHIFT:
modifier -= SHIFTED;
break;
case CTRL:
modifier -= CTRLED;
break;
default:
break;
}
}
}
ProcessMsgQueue(currentCons);
DeallocMem(KbdMsg);
break;
default:
DeallocMem(KbdMsg);
break;
}
}
}