Page 1 of 1

Problems with a command buffer

Posted: Sun Aug 02, 2009 1:23 am
by Andr3w
Hello,
There're some problems with my command buffer.

Code: Select all

unsigned shift_state = 0;
char kbd_buffer[128];
unsigned i;
bool bufchar;

/* Handles the keyboard interrupt */
void keyboard_handler(struct regs *r)
{
    unsigned char scan_code;
	
    /* Read from the keyboard's data buffer */
    scan_code = inportb(0x60);
	
	switch(scan_code)
	{
        case 0x2A: 
            shift_state = 1; 
            break;
 
        case 0xAA: 
            shift_state = 0;
            break;
 
        default:
			if (scan_code & 0x80)
			{
				bufchar = false;
			}
			else
			{
				if (kbdus[scan_code] == '\b')
				{
					bufchar = false;
					if (i > 0)
					{
						i--;
						putch(0);
						move_csr(i, csr_y);
					}
				}
				else if (kbdus[scan_code] == '\n')
				{
					putch('\n');
					kbd_buffer[i++] = '\0';
					exec_command(kbd_buffer);
					bufchar = false;
					i = 0;
				}
				else
				{
					putch((shift_state ? kbdus_shift:kbdus)[scan_code]);
					bufchar = true;
				}
			}
           break;
     }	 
	if (bufchar == true)
	{
		i++;
		kbd_buffer[i] = ((shift_state ? kbdus_shift:kbdus)[scan_code]);
	} 
    outportb(0x20,0x20);
}
For example: I type about in my Command Line, then press Backspace and then t and Enter, so there's "about' in my CLI.

But CLI can't found this command.

What's wrong with it?

--Andrew

Re: Problems with a command buffer

Posted: Sun Aug 02, 2009 1:52 am
by gzaloprgm
I found your error:

Code: Select all

if(bufchar==1){
i++;
kbd_buffer[i] = ((shift_state ? kbdus_shift:kbdus)[scan_code]);
}
should be

Code: Select all

if(bufchar==1){
kbd_buffer[i++] = ((shift_state ? kbdus_shift:kbdus)[scan_code]);
}
(you should increment the pointer AFTER writing the current char)

Cheers,
Gzaloprgm

Re: Problems with a command buffer

Posted: Sun Aug 02, 2009 4:22 am
by Andr3w
gzaloprgm wrote:I found your error:

Code: Select all

if(bufchar==1){
i++;
kbd_buffer[i] = ((shift_state ? kbdus_shift:kbdus)[scan_code]);
}
should be

Code: Select all

if(bufchar==1){
kbd_buffer[i++] = ((shift_state ? kbdus_shift:kbdus)[scan_code]);
}
(you should increment the pointer AFTER writing the current char)

Cheers,
Gzaloprgm
@gzaloprgm
Thank you!
(I noticed some mistakes, too: now it's working!) :)

Now I can make my Mouse Driver. :idea:

-- Andrew