OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Nov 24, 2020 9:18 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 8:43 am 
Offline

Joined: Tue Oct 20, 2020 10:38 am
Posts: 10
Code:
char kbdus[] = {
   0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0,
   '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
   '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`',
   0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0,
   '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
   '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};
char kbdus_shift[] = {
   0, 0, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', 0,
   '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}',
   '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '\"', '~',
   0, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 0,
   '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
   '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};
char kbdus_caps[] = {
   0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 0,
   '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']',
   '\n', 0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`',
   0, '\\', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 0,
   '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '7', '8', '9',
   '-', '4', '5', '6', '+', '1', '2', '3', '0', '.'
};

char keyConv(char rawinput)
{
   if(rawinput == (char)'\x12')
   {
      return kbdus_shift[(int)rawinput];
   }
   else if(rawinput == (char)'\x58')
   {
      return kbdus_caps[(int)rawinput];
   }
      else
   {
      return kbdus[(int)rawinput];
   }
}


This is my code at the end, it compiles but doesn't work


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 10:11 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3991
Location: Chichester, UK
SuperGabry64 wrote:
The fact is that the only programming i've done is object oriented, so something like ansi c or assembly is completely new to me

Forget OS development for the time being. Get a good book on C and learn how to program with simple user programs. Also, do the same for assembler. Then read the Intel Programmer's Manual so that you understand the processor. Then you will be in a position to attempt simple OS development.

You need to become proficient with your tools before you can build a fine piece of furniture.

As a matter of interest, what language did you use for object-oriented programming?


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 11:01 am 
Offline

Joined: Tue Oct 20, 2020 10:38 am
Posts: 10
I programmed in c# java python, but i did a little of c++ and javascript


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 11:10 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3991
Location: Chichester, UK
SuperGabry64 wrote:
I programmed in c# java python, but i did a little of c++ and javascript

In that case I'm extremely surprised that you have any problems with C.

But, my advice is still the same.


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 11:31 am 
Offline
Member
Member
User avatar

Joined: Fri Nov 22, 2019 5:46 am
Posts: 432
SuperGabry64 wrote:
Code:
char keyConv(char rawinput)
{
   if(rawinput == (char)'\x12')
   {
      return kbdus_shift[(int)rawinput];
   }
   else if(rawinput == (char)'\x58')
   {
      return kbdus_caps[(int)rawinput];
   }
      else
   {
      return kbdus[(int)rawinput];
   }
}

You are using the same char for deciding if shift/caps is pressed and as the "main" char. That makes no sense.

Greetings
Peter

_________________
https://wiki.osdev.org/User:PeterX


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Mon Oct 26, 2020 12:04 pm 
Offline
Member
Member
User avatar

Joined: Tue Sep 15, 2020 8:07 am
Posts: 155
Location: London, UK
PeterX wrote:
SuperGabry64 wrote:
Code:
char keyConv(char rawinput)
{
   if(rawinput == (char)'\x12')
   {
      return kbdus_shift[(int)rawinput];
   }
   else if(rawinput == (char)'\x58')
   {
      return kbdus_caps[(int)rawinput];
   }
      else
   {
      return kbdus[(int)rawinput];
   }
}

You are using the same char for deciding if shift/caps is pressed and as the "main" char. That makes no sense.

Greetings
Peter


Ok, SuperGabry64 I really do commend your dedication to this task, but you really need a lower level understanding of computer systems.

A char is a basic type, it’s 8 bits in length and is for most purposes the smallest unit of information you will interact with, if it has the value of 0x12 that’s the only information it contains, you cannot pass it to a function and expect there to be any more information there. Your code is treating the char as a single unit and expecting there to be both a shift key press and another key press to be encoded in that 8bit value, thus your code cannot work... Now things are going to get bumpy...

This does get a bit tricky with old hardware like the PS/2 controller as they will encode information in the various bit positions. Bit 7 is special when receiving data from the keyboard, in order to use the information you need to mask out the bits you aren’t interested in and then split the information out to use it. You will use the basic logical operations (& | ! ^)for this.

With a keyboard your driver might best be implemented as a state machine where your transitions can be triggered by the values you receive. If you don’t know what a state machine is then you have some fun homework tonight.

-edit- also you need to read about “casting” because you do it a lot in your code for no reason!

_________________
Building a single address space Microkernel, as used in embedded applications, for the desktop... Download latest build bootable Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Wed Oct 28, 2020 2:37 am 
Offline

Joined: Tue Oct 20, 2020 10:38 am
Posts: 10
However, i really need to know what is my mistake and how to implement it


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Wed Oct 28, 2020 3:03 am 
Offline
Member
Member
User avatar

Joined: Tue Sep 15, 2020 8:07 am
Posts: 155
Location: London, UK
SuperGabry64 wrote:
However, i really need to know what is my mistake and how to implement it


I tired to be as explicit as possible in my previous post.

I think the biggest issue you have is that your programming experience is with very high level languages. At the Operating System level, you have almost no support from the programming language (though once you have set up a stack, C does a lot of heavy lifting for you with respect to data structures and structured programming).

As I pointed out previously, the PS/2 controller encodes information at the bit level, you will need to learn about bitwise operations, and how to implement them with masks and combinatorial logic... this forum is not about teaching basic programming skills like this, but I’m happy to point you in the right direction.

_________________
Building a single address space Microkernel, as used in embedded applications, for the desktop... Download latest build bootable Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Wed Oct 28, 2020 3:05 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 72
SuperGabry64 wrote:
The fact is that the only programming i've done is object oriented, so something like ansi c or assembly is completely new to me


Even though I've heard you can build kernels with C++, I think it's gonna be hard to simultaneously learn C to advanced level, assembly to intermediate level and operating systems and x86 architecture.

I recommend first get really familiar with C and ok with assembly. Also, you might need to check the wiki for basic functioning of CPU and other systems.

Also, I don't know how much you understand the code in the tutorial(I haven't read it yet). I actually recommend building it from scratch as it will give you more experience that editing a template. First, just write a boot loader yourself and print something. Then, use the BIOS to do basic function. When you are OK with assembly, move on to 32-bit and communicate using ports and memory I/O. If you got C running with your boot loader, actually you can write anything and run it(excluding C lib functions). The fact that I am just implementing IDT after a text editor, interface and even half working interpreter means it's not that hard to write simple C programs and work it in your computer( although I don't recommend you do the same as it can affect your design decisions).


Also, you'll need to write substitutes for C library functions on your own. And some things is easier(for me) to do in assembly than C. So you may also learn how C works inside, to properly communicate with assembly code.

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Wed Oct 28, 2020 3:06 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3991
Location: Chichester, UK
Write your keyboard handling function as a simple user program to which you can input key codes. Run it under a debugger and watch what happens.

This really shouldn't be necessary - the error in your code has already been pointed out to you and is a very, very basic programming mistake.

My advice remains unchanged, You need to learn more about programming and simple data structures before you are ready to attempt OS development.


Top
 Profile  
 
 Post subject: Re: Keyboard input
PostPosted: Wed Oct 28, 2020 3:25 am 
Offline

Joined: Tue Oct 20, 2020 10:38 am
Posts: 10
1. Yes, i know that my experience is only with high level languages, in fact i'm learning c
2. Thank, i don't thinked of running in a debugger


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group