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.
Have you sent an End of Interrupt (EOI) to the appropriate PIC(s) when your IRQ handlers are finished? You also seem to be reading port 0x20? That is the master PIC.
Last edited by MichaelPetch on Sun Feb 24, 2019 1:51 am, edited 1 time in total.
These two need to test to see if the buffer is ready to receive a byte and if there is a byte in the buffer to read. Reading from an empty buffer will return undefined results.
Your code has a variety of issues. Perhaps the biggest is the name: you're trying to write a mouse driver, but most of the code you've written is for the PS/2 controller. Those are separate components, and you should name your functions appropriately to avoid confusion. I recommend also separating it into three drivers: one for the PS/2 controller, one for the mouse, and one for the keyboard.
Yes, the keyboard is also connected to the PS/2 controller. That's why your attempt at identifying the mouse causes the keyboard to stop responding.
Once you have clear separation between code that configures the PS/2 controller and code that configures the keyboard/mouse, I can help you more.
Octocontrabass wrote:Your code has a variety of issues. Perhaps the biggest is the name: you're trying to write a mouse driver, but most of the code you've written is for the PS/2 controller. Those are separate components, and you should name your functions appropriately to avoid confusion. I recommend also separating it into three drivers: one for the PS/2 controller, one for the mouse, and one for the keyboard.
Yes, the keyboard is also connected to the PS/2 controller. That's why your attempt at identifying the mouse causes the keyboard to stop responding.
Once you have clear separation between code that configures the PS/2 controller and code that configures the keyboard/mouse, I can help you more.
I have to second this. Octocontrabass' point is exactly what I was thinking but didn't comment at the time. I will add just a little to emphasize his point. On some PS/2 controllers, in fact more than not, you might have the mouse and the keyboard swapped and still work. I haven't tried it myself, but have read numerous sources that say it is available. With this in mind, dividing the drivers into three different sources is a very good point. (I had done this myself long ago)
hextakatt wrote:In kmain.c I have the mouse_printpos is in a infinite loop, but just prints zeros. And how I saided before, the keyboard does not work.
You're still mixing up the PS/2 controller and the mouse. Your "mouse_send_cmd" and "mouse_send_data" functions are sending commands and data to the PS/2 controller, not the mouse. You must separate the PS/2 controller functions from the mouse functions in your code.
The keyboard doesn't work because you're sending nonsense to the PS/2 controller, and the keyboard is connected to the PS/2 controller the same way the mouse is.
I managed to make the mouse driver work(¿?), but it is very sensitive, with moving the mouse a little the cursor is already in the corner of the screen. How can I change the sensitivity? Also it says that I pressed a mouse key when I not.
Edit:
mouse.c
hextakatt wrote:I managed to make the mouse driver work(¿?), but it is very sensitive, with moving the mouse a little the cursor is already in the corner of the screen. How can I change the sensitivity?
You mustn`t change sensitivity. You must write good driver for moving cursor. In LightningOS kernel 0.1.1 is moving cursor quite well with:
In fourth byte mouse send information about pressed keys. If in it is 0x10, left key is pressed. If in it is 0x20, right key is pressed. If in it is 0x40, middle key is pressed.
if (mouse_buffer[3] & 0x4) {
//middle key is pressed
}
if (mouse_buffer[3] & 0x2) {
//right key is pressed
}
if (mouse_bytes[3] & 0x1) {
//left key is pressed
}
I test it and it work in Bochs, Qemu and Virtualbox. Good luck!
Oh, sorry I didn't answer, I was busy.
Anyway, I don't know what made me think I would need a mouse driver, if I don't even have a GUI, or even a functional OS.
Thanks anyway, maybe it will help me someday!