To be more informative, the problem is that interrupts don't get called.
Brendan, I really appreciate your time and effort used on your long & very useful post.
The value in "cur" (at the "switch(cur)") would go 0, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, ... This is because for "case 2:" you set it to zero and then increment, so it ends up as 1.
I'm so blind... Fixed.
There's nothing to ensure that the mouse stays synchronised with the driver. If a byte goes missing or an extra byte is received for any reason, the driver will become "out of sync" and think that (e.g.) the first byte is the second, the second byte is the third, and the third byte is the first byte of the next packet for everything it receives after that. For mouse protocols there's always a "this bit is always set" flag somewhere that the driver should use to detect if it has become "out of sync" and auto-correct (so that it doesn't end up in a prolonged or permanent "out ouf sync" state and report garbage). It can also be a good idea to use timing information to assist in keeping driver in sync (e.g. if the time between receiving the first and second byte is greater than some threshold, or if the time between receiving the second and third byte is greater than some threshold, assume that something went wrong in the middle of the the previous packet and the byte you've just received is probably the first byte of a new packet).
Such PS/2 controller or mouse which does that would be easily clarified as faulty. Once this happened to me, when moving mouse to left made it go up, on Windows.
There's a variety of things you could receive that aren't handled ("echo/resend", "BAT" if user reconnects mouse, etc) that should be handled (and can/will put the driver into a "out of sync" state because they're not handled)
That is scheduled.
Immediately after the IRQ handler receives the third byte (and checks that it's likely to be correct, etc); there's no notification sent to the rest of the driver or anything else. This means that the rest of the driver or something else has to continually poll. Continual polling is extremely retarded. You need some form of "don't give me CPU time at all, until/unless I receive some kind of notification" capability in your scheduler (which typically takes the form of some kind of IPC - messages, pipes, etc).
The code assumes that a mouse exists and does no checking to make sure a mouse does exist. Assumptions like this guarantee that it will blow up in users' faces if the number of users ever increases.
(For these two above) First make it then improve
Through good advice
There is nothing that allows "extremely retarded continual polling" to be done without race conditions - e.g. the "MousePckt", "MposX" and "MposY" variables could be changed while someone is reading them, causing the reader to end up with "half and old packet combined with half a new packet".
I had troubled with such problems already (with keyboard, floppy driver, I don't remember what else) and that is one of very bad problems.
The code assumes that a mouse exists and does no checking to make sure a mouse does exist. Assumptions like this guarantee that it will blow up in users' faces if the number of users ever increases.
The code assumes that a PS/2 controller exists and does no checking to make sure the PS/2 controller exists. Assumptions like this guarantee that it will blow up in users' faces.
There is high possibility of that being a problem, since Bochs do not power-on with mouse connected.
I made it large so I would not miss it when I archive this thread. (phpBB could do that)
The code assumes that the mouse is using a specific protocol (e.g. "3 button mouse") and will fail if the mouse is using a different protocol (e.g. "5 button with scroll wheel"), and won't try to detect and enable better protocols. The end result is that (e.g.) if the mouse happens to be "5 button with scroll wheel" the driver will either send trash (wrong protocol) or the extra buttons and scroll wheel won't work.
As far I know InteliMouse extensions need to be enabled so they could start working.
The bytes received are not decoded properly for any mouse protocol. Don't forget that most mouse protocols use a "sign and magnitude" format for signed numbers and don't use "two's complement" (e.g. the raw byte 10000001b is -1 and not -127).
You probably did not readed my post.
Code: Select all
MposX+=mMsg; //For now let's not check for signed bit (I will not move mouse backwards ;) )
The mouse driver assumes it is allowed to mess with the PS/2 controller directly (and you're not using a separate PS/2 controller driver that talks to the mouse driver). This means that you can expect conflicts between different drivers for different PS/2 devices (e.g. starting or restarting a keyboard driver will probably screw up the mouse driver, starting or restarting the mouse driver will probably screw up the keyboard driver, etc). It also means that you'd have to rewrite the drivers if you ever want to support a different kind of PS/2 controller.
I have been wondered for this because it actually happened - when I would uncomment my MouseInit(); function, keyboard would stop working; while when I would return commenting again - Keyboard works instead of mouse.
The mouse driver can't work if the mouse is plugged into a different PS/2 port. For example, if I have a USB keyboard, a PS/2 mouse in the first PS/2 port, and a bar-code scanner in the second PS/2 port; then your code will assume that the bar-code scanner is a mouse and screw that up (while probably also assuming that the mouse is a keyboard and screwing that up).
Today PS/2 controller is being used just for backwards compatibility for keyboards and mices, through USB mices emulate most of PS/2. I should try coding a check is mouse connector inside.
The driver assumes that there are PIC chips (when sending EOI) and does not check if PIC chips exist and won't work if the OS is using IO APICs instead. You need to abstract this with some kind of "sendEOI()" kernel function, so that the driver/s can work regardless of whether PIC chips are being used or not.
I actually have that function but removed it from most places of my operating system. Instead I could probably just make it inline and return SendEOI(). Very good idea.
There's no "PS/2 controller sanity checking" (to determine if the PS/2 controller is usable or faulty), and no "PS/2 mouse sanity checking" (to determine if the mouse is usable or faulty). This means that as soon as the OS meets faulty hardware it will blow up in the user's face (rather than informing the user "Hey, this driver didn't start because your hardware is faulty", which allows the user to fix the problem and prevents the user from blaming the OS when it's not the OS's fault).
That is scheduled too.
Some software (most applications) want "absolute coordinates of mouse pointer" which needs to be scaled to the screen resolution and needs an acceleration curve, and some software (some games) need "relative movement". These are not the same; and you're providing neither (it looks like you're providing "absolute coordinates that aren't scaled, without acceleration curve").
Acceleration curve should not be hard to be integrated - I think that by moving mouse each , for example second should make mouse move two times faster than last second.
I'm not sure what should I do to scale it to screen. Don't I need to have DPI of screen?