Page 1 of 1

computer beeps when key pressed

Posted: Tue Mar 06, 2007 2:03 pm
by kubeos
Hello,

Newbie question. I am working on the keyboard driver and when I hit a key, it reads the scancode and returns what I want by reading from port 0x60. But on a real machine everytime i hit a key I get a beep from the speaker as well. Am I supposed to send something back to the keyboard to clear the buffer or something?

Thanks in advance.

Posted: Tue Mar 06, 2007 2:44 pm
by Combuster
If you are running in real mode, the bios might still be hooked up to the keyboard interrupt, which beeps when it gets many keypresses without calls to read the buffer. You will need to unhook the bios from IRQ1 to fix this (as well as any other problems it might be causing)

Posted: Tue Mar 06, 2007 4:07 pm
by Dex
Also have you sent a

Code: Select all

	mov   al,0x20
	out   0x20,al		                        ; quiet screaming irq chip.
After you read you should send the above, if your key function is called on IRQ.

stupid djgpp (or stupid me...)

Posted: Tue Mar 06, 2007 9:33 pm
by kubeos
Well, i was trying to code it in djgpp... I really just don't understand c that well I guess. I rewrote the routines in my own compiler and everything works perfect. No beeping or anything. So I'm gonna do the whole kernel in a c-- language.

Posted: Wed Mar 07, 2007 11:15 am
by bubach
that should be intresting.. do you have any webpage or blog or anything where people could read about your progress? someone might find a c-- resource useful.

hmmm..

Posted: Thu Mar 08, 2007 2:12 am
by kubeos
I have a page for kube at http://www.bc5.ca

But thats the old 16-bit version. As for the compiler, it's actually pretty awefull. It doesn't pass pointers to strings, it actually copies the string from its location to a global variable, then in the called function, it copies it from the global var into the functions var... the only reason I'm using it for my kernel is because it uses nasm as its assembler. So if anyone REALLY wants to program in c-- they should check out sphinx c--, its much better.

Anyway, once I've got a few things fixed with my 32-bit version of Kube, I'll post it on the site, and probably post the 32-bit version of my compiler as well, just in case anyone wants to see how terrible of a programmer I really am.

Posted: Thu Mar 08, 2007 5:14 am
by os64dev
So if anyone REALLY wants to program in c-- they should check out sphinx c--, its much better
ehh.. try gcc it is even better... at least if you are not doing real mode.

Posted: Thu Mar 08, 2007 5:57 am
by Brynet-Inc
os64dev wrote:
So if anyone REALLY wants to program in c-- they should check out sphinx c--, its much better
ehh.. try gcc it is even better... at least if you are not doing real mode.
os64dev, sphinx c-- is technically a different language.. Although it's just a strange hybrid language between ASM and C..

http://www.goosee.com/cmm/cpuspeed.c-- (Example of the syntax..)

http://www.goosee.com/cmm/

http://c--sphinx.narod.ru/indexe.htm

It's worth the effort just to learn Assembly/C and use GCC though..

getting off topic...

Posted: Thu Mar 08, 2007 12:03 pm
by kubeos
Well... I would prefer to use gcc anyway... So let me ask this.

How does gcc pass a string pointer?

eg..
extern int function(const char *something);
x=function("hello world");

in my asm function

global _function
_function:
push ebp
mov ebp,esp
sub esp,0x40
mov ebx,[ebp+8]
[CONFUSED ABOUT EBX???]
....more code
leave
ret

So what does ebx contain? Is it a pointer to the "hello world" string which I can use with edi or esi.. or is it something else.. If I can figure out the strings then I can probably continue with gcc.

Sorry, maybe I should have asked this in a new thread..

EDIT: forgot the extern on the function declaration.

Posted: Thu Mar 08, 2007 12:32 pm
by Combuster

Code: Select all

somewhere:
push string ; pushes pointer to string: string on stack
call function ; pushes eip on the stack: eip-string on stack

function:
push ebp ; pushed ebp: ebp-eip-string on stack
mov ebp, esp ;ebp points to ebp-eip-string
; ebp+4 points to eip
; ebp+8 points to string
mov ebx, [ebp+8] ; ebx points to null terminated string
...
mov al, [ebx] ; al is the first character in the string
inc ebx
mov al, [ebx] ; al is the second character in the string
...
leave ; restores esp and pops ebp
ret ; restores eip
I think this should do...