N00b: keyboard, dynamic linking, FAT/floppy, etc.

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.
Post Reply
amee2000

N00b: keyboard, dynamic linking, FAT/floppy, etc.

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:N00b having trouble with keyboard driver

Post 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 ! ...
amee2000

Re:N00b having trouble with keyboard driver

Post 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)
bluecode

Re:N00b having trouble with keyboard driver

Post 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.
amee2000

Re:N00b having trouble with keyboard driver

Post 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;
AR

Re:N00b having trouble with keyboard driver

Post 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;
amee2000

Re:N00b having trouble with keyboard driver

Post 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.
amee2000

Re:N00b having trouble with keyboard driver

Post by amee2000 »

I do

Code: Select all

PUSH BX
to save BX on the stack. Later I do

Code: Select all

POP  AX
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?
AR

Re:N00b having trouble with keyboard driver

Post 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.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:N00b having trouble with keyboard driver

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
amee2000

Re:N00b having trouble with keyboard driver

Post 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
Post Reply