Problems with a command buffer

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Problems with a command buffer

Post 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
User avatar
gzaloprgm
Member
Member
Posts: 141
Joined: Sun Sep 23, 2007 4:53 pm
Location: Buenos Aires, Argentina
Contact:

Re: Problems with a command buffer

Post 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
Visit https://gzalo.com : my web site with electronic circuits, articles, schematics, pcb, calculators, and other things related to electronics.
User avatar
Andr3w
Member
Member
Posts: 76
Joined: Tue Jun 09, 2009 4:09 am
Location: Somewhere

Re: Problems with a command buffer

Post 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
Post Reply