I am currenlty working on a xv6, I want to add an option when left shift + arrow up is pressed to return previously used command, something like history. I need help figuring out how to read when left shift is pressed
console.c file
#define BACKSPACE 0x100
#define CRTPORT 0x3d4
#define KEY_UP 0xE2
#define k 0x1C4
#define KEY_DN 0xE3
#define SHIFT 0x2A
#define CAPSLOCK 0x3A
int color = 0x0700;
static int flagShift = 0;
static ushort *crt = (ushort*)P2V(0xb8000); // CGA memory
static void
cgaputc(int c)
{
int pos;
int color = 0x0700;
// Cursor position: col + 80*row.
outb(CRTPORT, 14);
pos = inb(CRTPORT+1) << 8;
outb(CRTPORT, 15);
pos |= inb(CRTPORT+1);
if(c == 'n'){
pos += 80 - pos%80;
//cprintf("1");
}else if(c == BACKSPACE){
if(pos > 0) --pos;
}else if(c == SHIFT){
flagShift = 1;
}else{
if(flagShift == 0){
crt[pos++] = (c&0xff) | color; // black on white
}else{
crt[pos++] = (c&0xff) | 0x0000;
}
}
if(pos < 0 || pos > 25*80){
panic("pos under/overflow");
}
if((pos/80) >= 24){ // Scroll up.
memmove(crt, crt+80, sizeof(crt[0])*23*80);
pos -= 80;
memset(crt+pos, 0, sizeof(crt[0])*(24*80 - pos));
}
outb(CRTPORT, 14);
outb(CRTPORT+1, pos>>8);
outb(CRTPORT, 15);
outb(CRTPORT+1, pos);
crt[pos] = ' ' | 0x0700;
}
Shift map in kbd.h
#define SHIFT (1<<0)
static uchar shiftcode[256] =
{
[0x1D] CTL,
[0x2A] SHIFT,
[0x36] SHIFT,
[0x38] ALT,
[0x9D] CTL,
[0xB8] ALT
};
static uchar shiftmap[256] =
{
NO, 033, '!', '@', '#', '$', '%', '^', // 0x00
'&', '*', '(', ')', '_', '+', 'b', 't',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', // 0x10
'O', 'P', '{', '}', 'n', NO, 'A', 'S',
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', // 0x20
'"', '~', NO, '|', 'Z', 'X', 'C', 'V',
'B', 'N', 'M', '<', '>', '?', NO, '*', // 0x30
NO, ' ', NO, NO, NO, NO, NO, NO,
NO, NO, NO, NO, NO, NO, NO, '7', // 0x40
'8', '9', '-', '4', '5', '6', '+', '1',
'2', '3', '0', '.', NO, NO, NO, NO, // 0x50
[0x9C] 'n', // KP_Enter
[0xB5] '/', // KP_Div
[0xC8] KEY_UP, [0xD0] KEY_DN,
[0xC9] KEY_PGUP, [0xD1] KEY_PGDN,
[0xCB] KEY_LF, [0xCD] KEY_RT,
[0x97] KEY_HOME, [0xCF] KEY_END,
[0xD2] KEY_INS, [0xD3] KEY_DEL
};
When I tried this with capslock instead of shift capslock wasn’t working either so I guess I need help understanding how these specific buttons work.