[SOLVED] How to get string of input with basic IRQ driver?

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
RharryR
Posts: 17
Joined: Thu Feb 11, 2016 1:15 am
Location: Milingimbi Island, Australia

[SOLVED] How to get string of input with basic IRQ driver?

Post by RharryR »

Howdy!
I have written a IRQ keyboard driver, which works nice and dandy:

Code: Select all

// Generic Keyboard Driver
#include "include.h"

void kern_keyboard_int(struct regs* r)
{
	unsigned char code;
	code = inb(0x60);
	if(code & 0x80)
	{

	}
	
	else
	{

	}
	
}

void kern_setup_keyboard_driver()
{
	kern_put_str("Setting up generic keyboard driver...\n");
	kern_irq_place_handler(1, kern_keyboard_int);
}
Now heres the question: Im a writing a basic command line. How do I use this driver to get a string of input when I want it? I somehow need a readline function that returns a string(char*) of input, but how can I make the driver send the readline function keys? Hope you get what I mean.

Hazza
Last edited by RharryR on Fri Feb 12, 2016 2:45 am, edited 1 time in total.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How to get string of input with basic IRQ driver?

Post by BrightLight »

Start with get_char before get_string.
Anyway, your keyboard driver has to store the pressed keys in some sort of buffer, and your get_char function should read from that buffer and remove the character from it.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
RharryR
Posts: 17
Joined: Thu Feb 11, 2016 1:15 am
Location: Milingimbi Island, Australia

Re: How to get string of input with basic IRQ driver?

Post by RharryR »

omarrx024 wrote:Start with get_char before get_string.
Anyway, your keyboard driver has to store the pressed keys in some sort of buffer, and your get_char function should read from that buffer and remove the character from it.
Thanks for the reply. Could you demonstrate how I could do this? Im having a bit of trouble. Thanks again!!
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: [SOLVED] How to get string of input with basic IRQ drive

Post by BrightLight »

Psuedo-code might look like this:

Code: Select all

void keyboard_irq_handler()
{
	char scancode = inportb(0x60);

	// get ASCII char from scancode and put it in last_char
	last_char = get_ascii_char(scancode);		// psuedo-code
	kbd_irq = 1;					// notify that an IRQ has occured
}

char get_char()
{
	while(kbd_irq != 1);		// wait for an IRQ

	// now we know an IRQ occured
	// so just read the key

	kbd_irq = 0;
	return last_char;
}
You know your OS is advanced when you stop using the Intel programming guide as a reference.
ashishkumar4
Member
Member
Posts: 73
Joined: Wed Dec 23, 2015 10:42 pm

Re: [SOLVED] How to get string of input with basic IRQ drive

Post by ashishkumar4 »

That's a good question. I would like to share my own keyboard code with you. Its highly modular and easy to port though I wont suggest you to port my code into yours as I don't know what you have in your kernel. just go throw my code for any help. making a keyboard driver was a delicate task for me. you can use my scancodes and the basic idea from my keyboard driver which is get the scancode by quering the keyboard encoder/controller and match it with different cases. then use it to make a getch() func and then a getline func. if you want to use the backspace thing, you would have to write a code especially using your VGA I/O operations. Here are my code : (Not for just copy paste :3 )

https://github.com/AshishKumar4/Aqeous/ ... s/Keyboard (keyboard)
https://github.com/AshishKumar4/Aqeous/ ... /console.c (my console code)
The best method for accelerating a computer is the one that boosts it by 9.8 m/s2.
My OS : https://github.com/AshishKumar4/Aqeous
RharryR
Posts: 17
Joined: Thu Feb 11, 2016 1:15 am
Location: Milingimbi Island, Australia

Re: [SOLVED] How to get string of input with basic IRQ drive

Post by RharryR »

Thanks!! You guys are great!
Got my nice snazzy command line working :D
Post Reply