#include <config.h>
#include <stdio.h>
#include <l4/thread.h>
#include <l4/kip.h>
#include <l4/schedule.h>
#include <sdi/log.h>
#include <sdi/locator.h>
#include <sdi/panic.h>
#include <sdi/console.h>
#include <new>
#include <idl4glue.h>
#include <if/iflocator.h>
#include <if/iflogging.h>
#include <if/ifmemory.h>
#include <if/iffile.h>
uint32_t keyStatus;
L4_Bool_t reading = 1;
L4_ThreadId_t consoleid = L4_nilthread;
CORBA_Environment env (idl4_default_environment);
int CTRLpressed() {
return (keyStatus & 0x00000001) || (keyStatus & 0x00000002);
}
int ALTpressed() {
return (keyStatus & 0x00000004) || (keyStatus & 0x00000008);
}
int SHIFTpressed() {
return (keyStatus & 0x00000010) || (keyStatus & 0x00000020);
}
void setCTRL(int i) {
if(i) {
keyStatus |= 0x00000003;
} else {
keyStatus &= 0xfffffffc;
}
}
void setALT(int i) {
if(i) {
keyStatus |= 0x0000000c;
} else {
keyStatus &= 0xfffffff3;
}
}
void setSHIFT(int i) {
if(i) {
keyStatus |= 0x00000030;
} else {
keyStatus &= 0xffffffcf;
}
}
void ProcessInput(uint8_t scancode) {
if(0x01 == scancode) {
LogMessage("ESC - process screen control sequence");
reading = 0;
return;
} else if(0xe0 == scancode) {
keyStatus |= 0x10000000;
return;
} else if(scancode & 0x80) {
if((0xaa == scancode) || (0xb6 == scancode)) {
setSHIFT(0);
} else if(0xb8 == scancode) {
setALT(0);
} else if(0x9d == scancode) {
setCTRL(0);
}
} else {
if((0x2a == scancode) || (0x36 == scancode)) {
setSHIFT(1);
} else if(0x38 == scancode) {
setALT(1);
} else if(0x1d == scancode) {
setCTRL(1);
} else if(0x0e == scancode) {
writeConsole("\b");
} else if(0x1c == scancode) {
writeConsole("\n");
} else if(0x4b == scancode) {
writeConsole("%c[1D", 27);
} else if(0x4d == scancode) {
writeConsole("%c[1C", 27);
} else if(0x53 == scancode) {
writeConsole("%c", 127);
} else if(0x02 ==scancode && CTRLpressed()) {
writeConsole("%c[12C", 27);
} else if(0x03 ==scancode && CTRLpressed()) {
writeConsole("%c[12D", 27);
} else if(0x04 ==scancode && CTRLpressed()) {
writeConsole("%c[123C", 27);
} else if(0x05 ==scancode && CTRLpressed()) {
writeConsole("%c[123D", 27);
} else if(0x06 ==scancode && CTRLpressed()) {
writeConsole("%c[31m", 27);
} else if(0x07 ==scancode && CTRLpressed()) {
writeConsole("%c[0K", 27);
} else if(0x08 ==scancode && CTRLpressed()) {
writeConsole("%c[1K", 27);
} else if(0x09 ==scancode && CTRLpressed()) {
writeConsole("%c[2K", 27);
} else if(0x0a ==scancode && CTRLpressed()) {
writeConsole("%c[s", 27);
} else if(0x0b ==scancode && CTRLpressed()) {
writeConsole("%c[u", 27);
} else {
if(isPrintable(scancode, keyStatus)) {
char c = ScancodeToAscii(scancode, keyStatus);
writeConsole("%c", c);
}
}
}
}
int main()
{
printf ("Testclient1 is alive as thread %lx\n", L4_Myself().raw);
setenv("console#", "/console1", 0);
writeConsole("Press ESC to quit!\n");
size_t readsize = 256;
buffer_t inbuf;
inbuf._buffer = new CORBA_char[readsize];
inbuf._length = readsize;
inbuf._maximum = readsize;
while(reading) {
readConsole(readsize, &inbuf);
if(inbuf._length > 0) {
for(uint32_t i=0; i<inbuf._length; i++) {
uint8_t scancode = inbuf._buffer[i];
ProcessInput(scancode);
}
}
}
printf ("Testclient1 %lx finished.\n", L4_Myself().raw);
return 0;
}