Page 1 of 1
N00b: keyboard, dynamic linking, FAT/floppy, etc.
Posted: Sat Sep 03, 2005 8:07 am
by amee2000
Hi all!
(To make things easier for the beginning, I forgot about protected mode for the moment...)
I'm having my keyboard ISR up and running. To translate between scancodes and character codes I'm using an array of 128x2 bytes: the first byte for a normal keypress and the second one for a shifted keypress. Unfortunately I'm having trouble detecting the shift status. Keeping track of all the key press and releases is a pain. At 0x0000:0x0417 (
http://www.josheli.com/assembler/alang_ ... emory.html) should be a word telling me among other things about the shift status but the following code doesn't work 'cause it allways returns the non-shifted (lowercase) character:
Code: Select all
DS is correctly set, BX contains <offset address of my translation table>+<scancode>*2
MOV AX, 0x0000 ; load segment for keyboard status memory
MOV ES, AX
MOV AX, [ES:0x0417] ; load status word
AND AX, 0x0003 ; mask shift bits (bit0 and bit1)
JZ .load ; result zero means no modifier key pressed
INC BX ; otherwise select shifted character from keymap
.load
MOV AL, [DS:BX] ; load character
OR AL, AL ; filter unmatched scancodes
JZ .done
I don't think that any initialization is required to get current values from 0x0000:0x0417.
What am I missing?
Re:N00b having trouble with keyboard driver
Posted: Sat Sep 03, 2005 8:54 am
by Pype.Clicker
hmm, you should know that what's at 0x0000:0x04xx is the Bios Data Area. Under normal behaviour (e.g. in a DOS program), when the SHIFT key is hit, the keyboard interrupt from the BIOS is detecting this and setting the appropriate bit in the BDA. When "A" key is hit later on, you can rely on that state in the BDA.
Now, if you hook the keyboard interrupt to your own handler, nothing will keep updating the state in the BDA ! ...
Re:N00b having trouble with keyboard driver
Posted: Sat Sep 03, 2005 9:06 am
by amee2000
Does this mean none of whats on that page is acually availabe, contrariwise it is up to me to implement that behaviour? (if i need it - in fact I feel more like implementing a fifo buffer that contains already translated ASCII characters and keep the shift state private)
Re:N00b having trouble with keyboard driver
Posted: Sat Sep 03, 2005 10:51 am
by bluecode
You're right. Nothing in the bios data area is valid if you've set up your own keyboard isr. Implementing the bios behaviour is not that difficult: When you press/release SHIFT a simple scancode is send, which can be read at port 0x60. So the only thing you've to do is set/clear a bit in your application when you get one of these two scancodes.
Re:N00b having trouble with keyboard driver
Posted: Thu Sep 08, 2005 7:06 am
by amee2000
You shall love the online book "linker and loaders" ...
I'll read it
Next question: To ease disk access I'm writing a function that allows me to access BIOS drives in a LBA-like way.
I use INT 0x13, AH=0x08 to figure out the drive geometry and save the return values:
F_MAXSECT = <'Maximum sector number'>;
F_MAXCYL = <'Maximum cylinder number'>;
F_MAXHEAD = <'Maximum head number'>;
is this (c pseudo code) correct to convert the sector number to BIOS geometry:
AX=<# of sector>
Sector = AX % F_MAXSECT;
Cylinder = (AX / F_MAXSECT) % F_MAXCYL;
Head = AX / F_MAXSECT / F_MAXCYL;
Re:N00b having trouble with keyboard driver
Posted: Thu Sep 08, 2005 7:17 am
by AR
You know that the BIOS has LBA functions? (Although they can only be used on USB Flash, harddrives, CDROMs, etc, you still need CHS for floppies)
When I was messing around with a bootloader I wrote this for converting 64bit LBA to BIOS CHS geometry (it works):
Code: Select all
Sector = (LBA % FloppySectors) + 1; //FloppySectors=Sectors per Cylinder
Cylinder = (LBA / FloppySectors) / FloppyHeads;
Head = (LBA / FloppySectors) % FloppyHeads;
Re:N00b having trouble with keyboard driver
Posted: Thu Sep 08, 2005 7:46 am
by amee2000
(Although they can only be used on USB Flash, harddrives, CDROMs, etc, you still need CHS for floppies)
Thats why I convert it myself.
Thanks for the code. That explains why mine doesn't work.
Re:N00b having trouble with keyboard driver
Posted: Fri Sep 09, 2005 7:32 am
by amee2000
I do
to save BX on the stack. Later I do
to restore the value from BX in AX. VMWare reports:
[ASM-BOX_devel - Virtual Machine]
*** Virtual machine kernel stack fault (hardware reset) ***
...
There are no other PUSHs, POPs or CALLs between them but when I replace the "POP AX" with "POP BX" everything works fine. Why can't I pop a pushed register value to a different register?
Re:N00b having trouble with keyboard driver
Posted: Fri Sep 09, 2005 8:08 am
by AR
That is a valid operation, the CPU doesn't associate stack values with specific registers so it sounds like a bug in VMWare.
Re:N00b having trouble with keyboard driver
Posted: Fri Sep 09, 2005 8:31 am
by Brendan
Hi,
AR wrote:That is a valid operation, the CPU doesn't associate stack values with specific registers so it sounds like a bug in VMWare.
It's fairly common for values to be popped into different registers - so common that I'd be very surprised if it was a bug in VMware.
Instead, I wonder what happens with the registers
after EAX (or EBX) is popped, and if there's any other factors involved (an IRQ handler that doesn't save & restore the general registers it uses properly, or dodgy task switching code, etc).
In any case, have you tried Bochs or QEMU? They both let you step through the code one instruction at a time and allow you to view register contents, memory, stack, etc anytime you like - you'd be able to see exactly what is going on....
Cheers,
Brendan
Re:N00b having trouble with keyboard driver
Posted: Fri Sep 09, 2005 12:01 pm
by amee2000
No, I haven't but I think I'll get away from VMWare soon. There is also some strange behaviour with the disk access.
[edit] On a real box it works - It is an issue with VMWare (or at least the virtual machine environment)
[edit2] Not VM - Just got started with Bochs and it works fine... Think I throw VMWare out of my Bochs