I have a problem in my piano program -
i want to make a part in my program that is responsible for the color change in the piano keys in such a way that AS LONG AS A KEYBOARD KEY IS PRESSED the piano key that is related to the keyboard key will be BLUE (creating a delay that is reacting to the key press, or something) and the moment the finger is released from the key - it will turn white again.
i dont know how to create such a delay - now im using a fixed delay which is no good at all... sometimes when i press the same key twice fast it doesnt show the blue thing appropiately.
besides that, i need help in many more things... if someone will be willing to help me - i will appreciate it very much

thank you in advance
amit
Posted on 2002-04-25 08:30:05 by flipmode
What about coloring the key on WM_KEYDOWN, and uncoloring it on WM_KEYUP?
Posted on 2002-04-25 08:39:25 by f0dder
I am sorry i have never heared of those... im only a beginner in assembler, there are probably a dozen more simple ways to do what i have tried to do here...
please explain - what is WM_KEYDOWN and such ?
how can i use them in my program ?
thank you very much
Posted on 2002-04-25 09:24:03 by flipmode
Is there anyone out there who can check my program ? I know it seems like a lot of work but i feel like im doing things the wrong way... it was supposed to be simple and this program already passes the 300 lines, i just feel it shouldnt be that way.
If anyone is kind enough to help me here - i would be glad to send him my program as text or asm, every line has a comment.
Posted on 2002-04-25 09:32:58 by flipmode
flipmode, first take a look at iczelions tutorials http://win32asm.cjb.net

They will clearly explain what windows messages are and how to use them :)
Posted on 2002-04-25 09:54:40 by Hiroshimator
zip up your .asm file and post it here, somebody might take a look at it.
Posted on 2002-04-25 10:13:15 by f0dder
Thank you guys !

In response to your replies - i have taken a look at the tutorials, the thing is that my project is supposed to be kept simple. Without all that stuff that is posted there - that is too 'complicated' for me :)
If you would take a minute to look at my code you will notice there is nothing there more than the most basic things.
I dont even know what to say there isnt there because i dont know anything besides what i did hehe.
Anyway here is the zipped .asm file you can read as text.
I used borland turbo-assembler as my compiler...
Posted on 2002-04-25 14:26:15 by flipmode
I do not think Iczelions tutorials help you much; yours is a DOS program.
Posted on 2002-04-25 14:55:21 by CodeLover
i told you i dont have any idea what im doing anyway !
it seems that my program is a DOS program...
I just hope i will get help in time...
before my teacher kicks my but for not handing it over
Posted on 2002-04-25 15:08:34 by flipmode
I supposed that was a homework assignment.

If you really coded it entirely, you should know you are making a DOS program, you are working in 16 bits. As you see you are using interrupts, if you checked out Iczelion tutorials you might have noticed that the code shown there invokes API functions. You may also have noticed he is working in 32 bits.

In your case, I do not think Iczelion Tutorials can help you. Tell us exactly which part of your code does not work as you are expecting, I will not have problems helping you.
Posted on 2002-04-25 15:42:16 by CodeLover
Ok here is the piece of code i am currently having trouble with.
It is the part that relates to the graphical changes i am supposed to show when the user presses a chosen key. For example, if the user presses the 's' the program i supposed to redraw the first piano key in blue, instead of its original white.
So far so good, but - since after redrawing the key in blue i wish the key will turn white again, i dont know how to manage it in a way that AS LONG AS the s key is pressed, the program will perform some kind of a loop that will act as a delay, and the moment the s key is released, the program will quit the loop and continue to the next piece of code which will redraw the key in white again.
here is the specific s key example that i need help with, the same code i have for 12 other keys, which represnt the 12 other piano keys i have.

next0:
mov ah,01;
int 16h;
cmp al,'s'; compare key pressed to 's'
jne next1; next1 is another piece like this only for 'e'
mov si,3d6h; set appropiate position on screen
mov dh,0bh; set background as light blue
call key1; call appropriate drawing procedure
>here is the hard part for me, what piece of code should i inset here in order to generate the wanted effect ? i know it has something to do with int16h and buffer, but i really have no idea how to perform it.
Please help... my days are numbered and my doom is near :)
or something
Posted on 2002-04-25 15:57:17 by flipmode
What I used to do was trap IRQ1 (Int 09h if my memory serves me right). That way I could get the key-press and key-release codes, unlike from BIOS which only saves the key-press codes. Key press = WM_KEYDOWN, key release =WM_KEYUP.

Basically you're doing hardware level, BELOW BIOS. That way you can also determine if two keys are pressed at the same time. Better do some research on Int 09h and the keyboard. Stuff about DOS Extenders and PM will help since most of that stuff tends to require their own IRQ handlers.
Posted on 2002-04-25 17:45:42 by AmkG
Do you have an interrupt list? If not you can download it from this site
Posted on 2002-04-25 19:35:39 by CodeLover
i do have an interruprt list, and i heared of int16h but not that int1. whevern i use int16h it stucks my program, and i have to clear the buffer somehow (maybe turn ah back to 00 and call int16h again) i dont know
if anyone here knows anything about this - again, this is DOS program not WINDOWS - help
Posted on 2002-04-25 23:50:02 by flipmode
Well, you need to have a table of keyboard scan codes (this is different from the ascii codes) and you need to know which I/O port the keyboard is (it's pretty standard, I just can't remember it). Been a while since I did this sort of thing. :grin:

I've attached a file I though might be useful... haven't read this document for a while already... :-)
Posted on 2002-04-26 18:33:40 by AmkG
no such overhead needed... just use this as your
main loop...



_play: in al, 060h ;get current key

cmp al, 31 ;keycode for "s"
jnz _nope1 ;check next one
...
draw your piano-key or do
whatever has to be done...
...
_nope1: cmp al, ??
jnz _nope2 ;check next one
...
...
...

dec al ;escape = 1 so decrease...
jnz _play ;and check it


if you have problems then you should
disable interupts BEFORE and enable
them after you accessed port 60h (cli
& sti)...
Posted on 2002-04-26 21:24:16 by mob
i have got to admit that txt files looks very helpful ! :)
Thank you very much !
But, just a small 'issue' i have got here...
I have absolutely no clue in pascal, and the example program is given in it... Anyone here knows the smae code only in assembler ?
Posted on 2002-04-27 06:05:47 by flipmode
mob, i havent seen your post before i did mine
THANK YOU OH SO MUCH
I think this might be it :) :) :)
Posted on 2002-04-27 06:07:00 by flipmode
i dont understand mob...
how can the program tell if the key was just pressed or released in your piece of code ?
thats the whole thing, to know when was it released so i can call the procedure to turn the key into white again
Posted on 2002-04-27 06:13:32 by flipmode
I think it should be there in the text document, about key press and key release codes. You're doing direct hardware access.

mob,
In my mind-set that sort of thing is dangerous. Only IRQ1 is 'supposed' to have access to the keyboard. I wouldn't have done such a thing. 'Course presumably you know that it's correct... and likely it'll work anyway.

Still, if my memory serves me right, the keyboard I/O port would still hold the last key pressed, so as soon as the program gets run, the user would (presumably) have pressed enter key already, whose scan code would be left on the keyboard I/O port. At least by grabbing IRQ1, you can be sure that a key was pressed, and not a holdover from the last key-press.

Hmm, I'm rusty...
Posted on 2002-04-27 07:18:23 by AmkG