Page 1 of 1

Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Kattmat
Hm.. I went through a tutorial at Bona Fide that was about bootsectors and some C programming. In that tutorial you made your own bootsector in assembly and later on you did some printing to the screen in C. I thought I had all that cleared out; how it worked and so on. The C code I do understand, since I have been programming in C for quite some time. But the assembly code.. ugh! The bootsector code I do understand to a sertain point, since every line were described in the tutorial.

Now I want to add input support. If I press a key on the keyboard I want it to show up on the screen!  I looked around and found out that I need to have some interupts set up and that i need an IDT (what that now is) and stuff. Then I need to convert the keyboard scan codes into ASCII before I can print anything to the screen. But how? How to do all this? There is no tutorial that exactly goes through the process of programming a keyboard driver. I need some serious help over here..

Thanks major in advance!

ps.
  I'm looking for tutorials or understandable code. All the code I've seen up to this point have been to messy (which means that it does so much more than I want to learn at the moment so it is hard to part the stuff I want from the stuff I don't want; which makes it all pretty inunderstandeble).
ds.

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by gaffi
Here are some tutorials that may help you:

PIC, Interrupts and the IDT
http://www.osdever.net/tutorials.php?cat=5&sort=1

keyboard & scancode sets
http://panda.cs.ndsu.nodak.edu/~achapwes/PICmicro/
http://www.osdever.net/docs/kbd.php?the_id=14

PS: Interrupts aren't necessary to get data from the keyboard - you could also poll the keyboard. But since you'll need interrupts sooner or later anyway its's a good idea to set them up now.

Daniel Raffler

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Jamethiel
Good idea nothing. My Forth system had a working editor, compiler, hard disk driver, and keyboard driver before I set up the interrupts. And I set up the interrupts from -within the running system-.

It will be a lot simpler to write a polling-mode keyboard driver than to get interrupts working. As a first step, I recommend something that will print the keyboard scancode to the screen, without all that messy conversion to ASCII. That will let you know you have the hardware side of things working.

--Jamethiel

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Nick
I have just written my own 32bit pmode OS with paging (memory management), keyboard driver, file system, hard disk driver and multitasking.

The code for my keyboard driver is very simple in its self, but you need to setup a lot before it can work. Once you have an IDT and a PIC setup, then you can create any interrupt driver easily.

What you have to do is:
1) Move to 32bit PMODE
2) Setup a default (blank) IDT (Interrupt Descriptor Table).
3) Setup the PIC (Programmable Interrupt Controller)
3) Create the keyboard driver interrupt routine.
- Gets scancode and converts it to asci.
4) Enable IRQ 1 in the PIC and enable interrupts.

However, you do not need to do the above if you dont want a 32bit protected system with the possibility of easy expansion. You could just use bios, or poll the keyboard directly.

If you would like help with any part of it, or would like the source code to my OS, then email me at [email protected]. All my source code is simple (that is the aim of my OS).

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Kattmat
How to do that?

Thanks as usual! =)

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Jamethiel
This message board needs a search feature or something. This was on page 9 of the history:

http://www.osdev.org/board.jsp?message=2847

It explains (with code samples that nobody can use) how to write a polling-mode keyboard driver.

--Jamethiel

RE:Need a fresh start

Posted: Thu Jul 24, 2003 11:00 pm
by Kattmat
Since I suck at this real hard I can't get it to work..

What's wrong in this code: (my main.c code)

const char *teststring;

void main (void)
{
unsigned char input;

clrscr();
print( teststring );

while ( 1 ) {
input = in( 0x64 );
                if ( input && 1 ) {
input = in( 0x60 );
print( input );
}
}

for(;;);
}

const char *teststring = "Hello World!";


Thanks!