NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: ThatGuy22 on December 13, 2010, 07:47:12 PM
-
I wrote a program that prints out what the keyboard sends in port 0x60, but I have no idea how to translate these numbers to characters.
-please help.
-
Lookup table. See if the attached helps.
Best,
Frank
-
Ok so the numbers returned by port 0x60 correspond to key numbers on the keyboard, thanks
-But I get a different value when it is released how does that number correspond to the first number?
-
High bit is set. There are a few keys you need to keep track of the up/down state - shift, alt, control... - most of the time you can ignore the release interrupt.
Best,
Frank
-
When is the heigh bit set, when the key stroke is up, or down?
Also when you say heigh bit do you mean the left most bit such as 10000000 - binary value, 1 = set. In addition I am not entirely shure what the size of data is from port 0x60, I don't know if this is a variable length or it is always a certen length. Length being byte, word, dword, ext. Is the size always the same for all ports?
-
Key-down gives you the basic scancode, key-up gives you the basic scancode "or"ed with 80h. Yeah, it's the leftmost bit.
Some ports may allow you to read/write more than a byte. I'm not familiar with "all" the ports. The instructions exist:
in al, dx
in ax, dx
in eax, dx
I don't think you'll find anything more than a byte useful for keyboard, RTC, timer, etc. that you'll "probably" be using... at first, at least. Consult RBIL's "ports.lst".
Best,
Frank
-
So to get back to the original scan code you do this:
in al, 0x60
or al, 0x80
-So I understand, the left most bit tells you when the key is up or down and then once you get that you can get the key number?
Also how do you get the left most bit only, Ive seen other people do it except I still don't get how.
They also use and, or, xor sometimes - I fail to understand these completely, so if if you use one of them can you explain to me exactly what it does.
-
What you probably want is:
in al, 60h
test ah, 80h
jz key_down
; check for the few keys you care if they're up or down
; else, ignore
key_down:
; check for the few keys you care if they're up or down
; if so, set a bit somewhere to keep track of 'em
; if not, check for "modifiers" (is shift key down?)
; look it up
; stuff it in keyboard buffer
As you can see from that "int9.asm" I posted (originally from Randy Hyde's AoA, unless I'm mistaken) there's more to it than that - a number of "special cases" that need to be checked - but that's the general idea.
The code you posted:
in al, 0x60
or al, 0x80
Will convert a "down" scancode into an "up" scancode - probably not very useful.
If you need to know what the instructions do, Intel and AMD have nice manuals. There was an instruction set reference in old Nasm manuals (removed because we didn't have anyone to maintain it). It is obsolete, buggy, and doesn't have any information on flags. I "rescued" it, because it's in "Nasm syntax"... and because I'm "used to it".
http://home.myfairpoint.net/fbkotler/nasmdocr.html
Might be a good idea to learn the instructions before you attempt to write an OS with 'em. :)
Best,
Frank
-
ok thanks, i'll take a look at more advanced instructions.
Ive been only been using mov, jmp, cmp.
Also if I were to take the high bit of the key up scan code and make it 0 would it give me the down scan code?
-If so this would mean that the reason I get a different character from dos is because, the high bit is modifying the number.
-
Yeah, I guess.
in al, 60h
and al, 7Fh
That's still only going to give you the scancode, though. The only scancode I know off the top of my head is from the escape key: 1. (they're just row/column of the key, I think). If you try to print a 1 in dos, it'll be a "smiley face", as I recall. What may serve you well at this point would be to display al as binary...
;--------------
al2bin:
push ax
push bx
push cx
mov bx, 7 ; "just in case" for int 10h
mov cx, 8 ; 8 bits to do
.top:
rcl al, 1 ; high bit rotates to low bit - and into carry flag
push ax ; save our "number"
mov al, '0'
adc al, 0 ; "add with carry" - make al '0' or '1'
mov ah, 0Eh
int 10h
pop ax
loop .top
; do a newline? you may not want this...
mov al, 13
mov ah, 0Eh
int 10h
mov al, 10
mov ah, 0Eh
int 10h
pop cx
pop bx
pop ax
ret
;---------------
That's untested (as 16-bit code - modified from a routine that worked in Linux). If it broke, you can fix it... :)
Best,
Frank
-
ok thanks.